public <T> BiConsumer<T, ? super Throwable> getCompletionDeferred() { return (ignore, e) -> { if (e != null) { if (e instanceof CompletionException) { e = e.getCause(); } failIteration(e); return; } completeIteration(); }; }
public <T> BiConsumer<T, ? super Throwable> getCompletionDeferred() { return (ignore, e) -> { if (e != null) { if (e instanceof CompletionException) { e = e.getCause(); } failIteration(e); return; } completeIteration(); }; }
public CompletionHandler getSafeHandler(TestContext ctx, CompletionHandler handler) { return (o, e) -> { try { handler.handle(o, e); ctx.completeIteration(); } catch (Throwable t) { ctx.failIteration(t); } }; }
public CompletionHandler getSafeHandler(TestContext ctx, CompletionHandler handler) { return (o, e) -> { try { handler.handle(o, e); ctx.completeIteration(); } catch (Throwable t) { ctx.failIteration(t); } }; }
private <T> BiConsumer<T, ? super Throwable> getExpectedExceptionCompletion(TestContext ctx) { return (ignore, ex) -> { try { Assert.assertNotNull(ex); if (ex instanceof CompletionException) { Assert.assertNotNull(ex.getCause()); ex = ex.getCause(); } Assert.assertEquals(TestException.class, ex.getClass()); ctx.completeIteration(); } catch (Throwable e) { ctx.failIteration(e); } }; }
private <T> BiConsumer<T, ? super Throwable> getExpectedExceptionCompletion(TestContext ctx) { return (ignore, ex) -> { try { Assert.assertNotNull(ex); if (ex instanceof CompletionException) { Assert.assertNotNull(ex.getCause()); ex = ex.getCause(); } Assert.assertEquals(TestException.class, ex.getClass()); ctx.completeIteration(); } catch (Throwable e) { ctx.failIteration(e); } }; }
public void failIteration(Throwable e) { if (this.isSingleton) { throw new IllegalStateException("Use startTest on singleton, shared host instances"); } if (isStopping()) { log("Received completion after stop"); return; } TestContext ctx = this.context; if (ctx == null) { log("Test finished, ignoring completion. This might indicate wrong count was used in testStart(count)"); return; } log("test failed: %s", e.toString()); ctx.failIteration(e); }
public void failIteration(Throwable e) { if (this.isSingleton) { throw new IllegalStateException("Use startTest on singleton, shared host instances"); } if (isStopping()) { log("Received completion after stop"); return; } TestContext ctx = this.context; if (ctx == null) { log("Test finished, ignoring completion. This might indicate wrong count was used in testStart(count)"); return; } log("test failed: %s", e.toString()); ctx.failIteration(e); }
private <T> T doGet(TestManagementHost host, Class<T> clazz, URI uri) throws Throwable { TestContext ctx = BaseTestCase.testCreate(1); AtomicReference<T> result = new AtomicReference<>(); Operation op = Operation.createGet(uri) .setReferer(host.getUri()) .setCompletion((o, e) -> { if (e == null) { result.set(o.getBody(clazz)); ctx.completeIteration(); } else { ctx.failIteration(e); } }); host.sendRequest(op); ctx.await(); return result.get(); }
@Test public void testInvalidSessionShouldFail() { TestContext ctx = testCreate(1); Operation get = Operation.createGet(host, ManagementUriParts.AUTH_LOGOUT) .setReferer(host.getUri()) .setCompletion((o, ex) -> { if (ex != null && ex instanceof IllegalAccessError) { ctx.completeIteration(); return; } ctx.failIteration(new IllegalStateException()); }); host.send(get); ctx.await(); }
protected SecurityContext getSecurityContext() { final SecurityContext[] context = new SecurityContext[1]; TestContext ctx = testCreate(1); host.send(Operation.createGet(host, SessionService.SELF_LINK) .setCompletion((o, ex) -> { if (ex != null) { ctx.failIteration(ex); return; } context[0] = o.getBody(SecurityContext.class); ctx.completeIteration(); })); ctx.await(); return context[0]; }
private <T> void doDelete(TestManagementHost host, URI uri) throws Throwable { TestContext ctx = BaseTestCase.testCreate(1); Operation op = Operation.createDelete(uri) .setReferer(host.getUri()) .setCompletion((o, e) -> { if (e == null) { ctx.completeIteration(); } else { ctx.failIteration(e); } }); host.sendRequest(op); ctx.await(); }
protected SecurityContext getSecurityContext(String principalId) { final SecurityContext[] context = new SecurityContext[1]; TestContext ctx = testCreate(1); host.send(Operation.createGet(host, UriUtils.buildUriPath(PrincipalService.SELF_LINK, principalId, PrincipalService.SECURITY_CONTEXT_SUFFIX)) .setCompletion((o, ex) -> { if (ex != null) { ctx.failIteration(ex); return; } context[0] = o.getBody(SecurityContext.class); ctx.completeIteration(); })); ctx.await(); return context[0]; }
private void updateExampleService(String txid, URI exampleServiceUri, ExampleServiceState exampleServiceState) throws Throwable { TestContext ctx = testCreate(1); Operation put = Operation .createPut(exampleServiceUri) .setTransactionId(txid) .setBody(exampleServiceState) .setCompletion((o, e) -> { if (e != null) { ctx.failIteration(e); return; } ctx.completeIteration(); }); this.defaultHost.send(put); testWait(ctx); }
private void queryTemplateImages() { TestContext ctx = BaseTestCase.testCreate(1); host.sendRequest(Operation.createGet(UriUtils.buildUri(host, templateQuery)) .setReferer(host.getUri()) .setCompletion((o, ex) -> { if (ex != null) { ctx.failIteration(ex); } else { ctx.completeIteration(); } })); ctx.await(); }
public void delete(String selfLink) throws Throwable { TestContext ctx = testCreate(1); Operation delete = Operation .createDelete(UriUtils.buildUri(host, selfLink)) .setBody(new ServiceDocument()) .setCompletion((o, e) -> { if (e != null) { ctx.failIteration(e); return; } ctx.completeIteration(); }); host.send(delete); ctx.await(); }
public void deleteUser(String user) { TestContext ctx = testCreate(1); Operation delete = Operation.createDelete(host, AuthUtil .buildUserServicePathFromPrincipalId(user)) .setReferer(host.getUri()) .setCompletion((o, ex) -> { if (ex != null) { ctx.failIteration(ex); return; } ctx.completeIteration(); }); host.send(delete); ctx.await(); }
public void deleteUserGroup(String userGroup) { TestContext ctx = testCreate(1); Operation delete = Operation .createDelete(host, UriUtils.buildUriPath(UserGroupService.FACTORY_LINK, userGroup)) .setReferer(host.getUri()) .setCompletion((o, ex) -> { if (ex != null) { ctx.failIteration(ex); return; } ctx.completeIteration(); }); host.send(delete); ctx.await(); }
protected void doPatch(Object state, String documentSelfLink) { TestContext ctx = testCreate(1); Operation patch = Operation.createPatch(host, documentSelfLink) .setBody(state) .setReferer(host.getUri()) .setCompletion((o, ex) -> { if (ex != null) { ctx.failIteration(ex); return; } ctx.completeIteration(); }); host.send(patch); ctx.await(); }
@Override protected void doPatch(Object state, String documentSelfLink) { TestContext ctx = testCreate(1); Operation patch = Operation.createPatch(host, documentSelfLink) .setBody(state) .setReferer(host.getUri()) .setCompletion((o, ex) -> { if (ex != null) { ctx.failIteration(ex); return; } ctx.completeIteration(); }); host.send(patch); ctx.await(); }