Refine search
private static Builder handleHeartbeat(EurekaServerConfig config, InstanceResource resource, String lastDirtyTimestamp, String overriddenStatus, String instanceStatus) { Response response = resource.renewLease(REPLICATION, overriddenStatus, instanceStatus, lastDirtyTimestamp); int responseStatus = response.getStatus(); Builder responseBuilder = new Builder().setStatusCode(responseStatus); if ("false".equals(config.getExperimental("bugfix.934"))) { if (responseStatus == Status.OK.getStatusCode() && response.getEntity() != null) { responseBuilder.setResponseEntity((InstanceInfo) response.getEntity()); } } else { if ((responseStatus == Status.OK.getStatusCode() || responseStatus == Status.CONFLICT.getStatusCode()) && response.getEntity() != null) { responseBuilder.setResponseEntity((InstanceInfo) response.getEntity()); } } return responseBuilder; }
Form form = new Form(); form.add("x", "foo"); form.add("y", "bar"); Client client = ClientBuilder.newClient(); WebTarget resource = client.target("http://localhost:8080/someresource"); Builder request = resource.request(); request.accept(MediaType.APPLICATION_JSON); Response response = request.get(); if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) { System.out.println("Success! " + response.getStatus()); System.out.println(response.getEntity()); } else { System.out.println("ERROR! " + response.getStatus()); System.out.println(response.getEntity()); }
@Test public void testErrorDELETE() { final Response response = abstractListenerHandler.handleDELETE(error_id); Assert.assertEquals(500, response.getStatus()); Assert.assertEquals(ImmutableMap.of("error", error_msg), response.getEntity()); }
@Test public void testGetTasksNegativeState() { EasyMock.replay(taskRunner, taskMaster, taskStorageQueryAdapter, indexerMetadataStorageAdapter, req); Object responseObject = overlordResource .getTasks("blah", "ds_test", null, null, null, req) .getEntity(); Assert.assertEquals( "Invalid state : blah, valid values are: [pending, waiting, running, complete]", responseObject.toString() ); }
@Test public void shoudlFailIfCannotWriteTerminateCommand() throws InterruptedException { // Given: when(commandStore.enqueueCommand(any(), any(), any(), any())).thenThrow(new KsqlException("")); // When: final Response response = ksqlResource.terminateCluster(VALID_TERMINATE_REQUEST); // Then: assertThat(response.getStatus(), equalTo(500)); assertThat(response.getEntity().toString(), CoreMatchers .startsWith("Could not write the statement 'TERMINATE CLUSTER;' into the command ")); }
@SuppressWarnings({"ConstantConditions"}) private int getNumSubTasks(Function<SinglePhaseParallelIndexingProgress, Integer> func) { final Response response = task.getProgress(newRequest()); Assert.assertEquals(200, response.getStatus()); return func.apply((SinglePhaseParallelIndexingProgress) response.getEntity()); }
@Test public void testHandleAll() { final Response response = abstractListenerHandler.handleGETAll(); Assert.assertEquals(200, response.getStatus()); Assert.assertEquals(all, response.getEntity()); }
@Test public void testGetClusterServersSimple() throws Exception { Response res = serversResource.getClusterServers(null, "simple"); String result = objectMapper.writeValueAsString(res.getEntity()); String expected = "[{\"host\":\"host\",\"tier\":\"tier\",\"type\":\"historical\",\"priority\":0,\"currSize\":1,\"maxSize\":1234}]"; Assert.assertEquals(expected, result); }
@Test public void shouldReturnCorrectResponseForUnspecificException() { final Response response = exceptionMapper.toResponse(new Exception("error msg")); assertThat(response.getEntity(), instanceOf(KsqlErrorMessage.class)); final KsqlErrorMessage errorMessage = (KsqlErrorMessage)response.getEntity(); assertThat(errorMessage.getMessage(), equalTo("error msg")); assertThat(errorMessage.getErrorCode(), equalTo(Errors.ERROR_CODE_SERVER_ERROR)); assertThat(response.getStatus(), equalTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())); } }
@Test public void shouldReturnValidJSON() throws Exception { Response response = testDiscoveryService().getDiscoveryDocument( uriInfo( baseUri ) ); String json = new String( (byte[]) response.getEntity() ); assertNotNull( json ); assertThat( json.length(), is( greaterThan( 0 ) ) ); assertThat( json, is( not( "\"\"" ) ) ); assertThat( json, is( not( "null" ) ) ); }
private <T> void assertEqualsJsonResponse(Response expected, Response actual, Class<T> entityClass) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); T entityFromExpected = objectMapper.readValue((String) expected.getEntity(), entityClass); T actualFromExpected = objectMapper.readValue((String) expected.getEntity(), entityClass); assertEquals(entityFromExpected, actualFromExpected); assertEquals(expected.getStatus(), actual.getStatus()); assertTrue(expected.getHeaders().equalsIgnoreValueOrder(actual.getHeaders())); } }
Form form = new Form(); form.add("x", "foo"); form.add("y", "bar"); ClientResource resource = new ClientResource("http://localhost:8080/someresource"); Response response = resource.post(form.getWebRepresentation()); if (response.getStatus().isSuccess()) { System.out.println("Success! " + response.getStatus()); System.out.println(response.getEntity().getText()); } else { System.out.println("ERROR! " + response.getStatus()); System.out.println(response.getEntity().getText()); }
@Test public void testExceptionalHandleAll() { shouldFail.set(true); final Response response = abstractListenerHandler.handleGETAll(); Assert.assertEquals(500, response.getStatus()); Assert.assertEquals(ImmutableMap.of("error", error_message), response.getEntity()); }
@Test public void testGetClusterServersFull() throws Exception { Response res = serversResource.getClusterServers("full", null); String result = objectMapper.writeValueAsString(res.getEntity()); String expected = "[{\"host\":\"host\"," + "\"maxSize\":1234," + "\"type\":\"historical\"," + "\"tier\":\"tier\"," + "\"priority\":0," + "\"segments\":{\"dataSource_2016-03-22T14:00:00.000Z_2016-03-22T15:00:00.000Z_v0\":" + "{\"dataSource\":\"dataSource\",\"interval\":\"2016-03-22T14:00:00.000Z/2016-03-22T15:00:00.000Z\",\"version\":\"v0\",\"loadSpec\":{},\"dimensions\":\"\",\"metrics\":\"\"," + "\"shardSpec\":{\"type\":\"none\"},\"binaryVersion\":null,\"size\":1,\"identifier\":\"dataSource_2016-03-22T14:00:00.000Z_2016-03-22T15:00:00.000Z_v0\"}}," + "\"currSize\":1}]"; Assert.assertEquals(expected, result); }
@Test public void shouldReturnCorrectResponseForWebAppException() { final WebApplicationException webApplicationException = new WebApplicationException("error msg", 403); final Response response = exceptionMapper.toResponse(webApplicationException); assertThat(response.getEntity(), instanceOf(KsqlErrorMessage.class)); final KsqlErrorMessage errorMessage = (KsqlErrorMessage)response.getEntity(); assertThat(errorMessage.getMessage(), equalTo("error msg")); assertThat(errorMessage.getErrorCode(), equalTo(40300)); assertThat(response.getStatus(), equalTo(403)); }
@Test public void getConfiguration() { Response response = mHandler.getConfiguration(); try { assertNotNull("Response must be not null!", response); assertNotNull("Response must have a entry!", response.getEntity()); assertTrue("Entry must be a SortedMap!", (response.getEntity() instanceof SortedMap)); SortedMap<String, String> entry = (SortedMap<String, String>) response.getEntity(); assertFalse("Properties Map must be not empty!", (entry.isEmpty())); } finally { response.close(); } }
private KsqlErrorMessage makeFailingRequest(final KsqlRequest ksqlRequest, final Code errorCode) { try { final Response response = ksqlResource.handleKsqlStatements(ksqlRequest); assertThat(response.getStatus(), is(errorCode.getCode())); assertThat(response.getEntity(), instanceOf(KsqlErrorMessage.class)); return (KsqlErrorMessage) response.getEntity(); } catch (final KsqlRestException e) { return (KsqlErrorMessage) e.getResponse().getEntity(); } }
@Test public void testHandleSimpleDELETE() { final Response response = abstractListenerHandler.handleDELETE(valid_id); Assert.assertEquals(202, response.getStatus()); Assert.assertEquals(obj, response.getEntity()); }
@Test public void testGetServerSimple() throws Exception { Response res = serversResource.getServer(server.getName(), "simple"); String result = objectMapper.writeValueAsString(res.getEntity()); String expected = "{\"host\":\"host\",\"tier\":\"tier\",\"type\":\"historical\",\"priority\":0,\"currSize\":1,\"maxSize\":1234}"; Assert.assertEquals(expected, result); }