@Benchmark public Response post() throws Exception { return client.target("foo").request().post(Entity.text("bar")); }
/** * Send message to webapp to refresh SearcherManagers for given projects. * This is used for partial reindex. * * @param subFiles list of directories to refresh corresponding SearcherManagers * @param host the host address to receive the configuration */ public void signalTorefreshSearcherManagers(List<String> subFiles, String host) { // subFile entries start with path separator so get basename // to convert them to project names. subFiles.stream().map(proj -> new File(proj).getName()).forEach(project -> { Response r = ClientBuilder.newClient() .target(host) .path("api") .path("v1") .path("system") .path("refresh") .request() .put(Entity.text(project)); if (r.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { LOGGER.log(Level.WARNING, "Could not refresh search manager for {0}", project); } }); }
@Benchmark public Future<Response> asyncEntityIgnore() throws Exception { return client.target("foo").request().async().post(Entity.text("bar"), new InvocationCallback<Response>() { @Override public void completed(final Response response) { // NOOP } @Override public void failed(final Throwable throwable) { // NOOP } }); }
@Override public EurekaHttpResponse<Void> statusUpdate(String asgName, ASGStatus newStatus) { Response response = null; try { String urlPath = "asg/" + asgName + "/status"; response = jerseyClient.target(serviceUrl) .path(urlPath) .queryParam("value", newStatus.name()) .request() .header(PeerEurekaNode.HEADER_REPLICATION, "true") .put(Entity.text("")); return EurekaHttpResponse.status(response.getStatus()); } finally { if (response != null) { response.close(); } } }
@Override Invocation makeInvocation(WebTarget target, String user, String item, String strength) { return target.path("/pref/" + user + "/" + item).request() .buildPost(Entity.text(strength)); } },
private void markProjectIndexed(Project project) { RuntimeEnvironment env = RuntimeEnvironment.getInstance(); // Successfully indexed the project. The message is sent even if // the project's isIndexed() is true because it triggers RepositoryInfo // refresh. if (project != null) { // Also need to store the correct value in configuration // when indexer writes it to a file. project.setIndexed(true); if (env.getConfigURI() != null) { Response r = ClientBuilder.newClient() .target(env.getConfigURI()) .path("api") .path("v1") .path("projects") .path(Util.URIEncode(project.getName())) .path("indexed") .request() .put(Entity.text("")); if (r.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { LOGGER.log(Level.WARNING, "Couldn''t notify the webapp that project {0} was indexed: {1}", new Object[] {project, r}); } } } }
@Test public void testNoPreference() { Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(), target("/pref/U2/I2").request().post(Entity.text("aBc!")).getStatus()); }
@Test public void testNoIngest() { Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(), target("/ingest").request().post(Entity.text(IngestTest.INGEST_DATA)).getStatus()); }
@Test public void testNoTrain() { Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(), target("/train").request().post(Entity.text(TrainTest.TRAIN_DATA)).getStatus()); }
@Test public void testPostWithBadItemValue() { Response response = target("/pref/U2/I2").request().post(Entity.text("aBc!")); Assert.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); }
@Test public void testNoAdd() { Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(), target("/add").request().post(Entity.text(AddTest.ADD_DATA)).getStatus()); }
@Test public void pureGsonRoundtrip() { List<String> result = client.target(SERVER_URI) .path("/") .request(MediaType.TEXT_PLAIN_TYPE) .accept(MediaType.TEXT_PLAIN_TYPE) .post(Entity.text(Collections.singletonList("11")), new GenericType<List<String>>() {}); check(result).isOf("x", "y", "[11]"); }
@Test public void testPredictPost() { String prediction = target("/predict").request().post(Entity.text("A,-5,\nB,0,")) .readEntity(String.class); double expectedValue1 = (1.0 + 2.0 * 100.0) / 3.0; double expectedValue2 = (10.0 + 2 * 1000.0) / 3; Assert.assertEquals(expectedValue1 + "\n" + expectedValue2 + "\n", prediction); }
@Test public void testAssignPost() { String prediction = target("/assign").request().post(Entity.text("-1.5,0.5\n-1,0")) .readEntity(String.class); Assert.assertEquals("4\n4\n", prediction); }
@Test public void testSimpleIngest() { checkResponse(target("/ingest").request().post(Entity.text(INGEST_DATA))); }
@Test public void testPostWithEmptyItemValue() { Response response = target("/pref/U2/I2").request().post(Entity.text("")); checkResponse(response, "U2", "I2", "1"); }
@Test public void testURITrain() throws Exception { Response response = target("/train/" + TRAIN_DATA.split("\n")[0]) .request().post(Entity.text("")); Assert.assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus()); List<Pair<String,String>> data = MockTopicProducer.getData(); Assert.assertEquals(1, data.size()); Assert.assertArrayEquals(EXPECTED_TOPIC[0], data.get(0).getSecond().split(",")); }
@Test public void testSimpleAdd() { checkResponse(target("/add").request().post(Entity.text(ADD_DATA))); }
@Test public void testSimpleTrain() { checkResponse(target("/train").request().post(Entity.text(TRAIN_DATA))); }
@Test public void testURIAdd() throws Exception { Response response = target("/add/" + ADD_DATA.split("\n")[0]).request().post(Entity.text("")); Assert.assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus()); List<Pair<String,String>> data = MockTopicProducer.getData(); Assert.assertEquals(1, data.size()); Assert.assertArrayEquals(EXPECTED_TOPIC[0], data.get(0).getSecond().split(",")); }