/** * Sends an operation and waits for completion. CompletionHandler on passed operation will be cleared. */ public void sendAndWaitExpectSuccess(Operation op) { // to be compatible with old behavior, clear the completion handler op.setCompletion(null); this.sender.sendAndWait(op); }
private void createEndpointExpectFailure(EndpointSpec e, Consumer<TestRequestSender.FailureResponse> consumer) { Operation o = Operation .createPut(host, PKSCreateEndpointService.SELF_LINK) .setBodyNoCloning(e); TestRequestSender.FailureResponse failure = sender.sendAndWaitFailure(o); consumer.accept(failure); }
private RegistryState getHarborRegistry(boolean exists) { if (exists) { return sender.sendGetAndWait(UriUtils.buildUri(host, Harbor.DEFAULT_REGISTRY_LINK), RegistryState.class); } else { FailureResponse failureResponse = sender.sendAndWaitFailure( Operation.createGet(host, Harbor.DEFAULT_REGISTRY_LINK)); assertEquals(Operation.STATUS_CODE_NOT_FOUND, failureResponse.op.getStatusCode()); return null; } }
private void verifyCurrentQuorum(TestNodeGroupManager manager, int expectedQuorum) { ServiceHost node = manager.getHost(); TestRequestSender sender = new TestRequestSender(node); String nodeGroupPath = UriUtils.buildUriPath(ServiceUriPaths.NODE_GROUP_FACTORY, manager.getNodeGroupName()); Operation op = Operation.createGet(node, nodeGroupPath); NodeGroupState nodeGroupState = sender.sendAndWait(op, NodeGroupState.class); nodeGroupState.nodes.values().forEach( nodeState -> assertEquals("quorum on host=" + nodeState.id, expectedQuorum, nodeState.membershipQuorum)); }
@Test public void testAddRemoveTopic() throws Throwable { EventTopicState state1 = createTopicState("substage1", "topic1"); EventTopicState state2 = createTopicState("substage2", "topic2"); EventTopicState state3 = createTopicState("substage3", "topic3"); Map<String, Duration> map = getTimeoutsPerStageAndSubstage(); assertNotNull(map); URI uri = UriUtils.buildUri(host, EventTopicService.FACTORY_LINK); EventTopicState result1 = sender .sendPostAndWait(uri, state1, EventTopicState.class); assertNotNull(result1); verifyMapSize(map, 1); EventTopicState result2 = sender .sendPostAndWait(uri, state2, EventTopicState.class); assertNotNull(result2); verifyMapSize(map, 2); EventTopicState result3 = sender .sendPostAndWait(uri, state3, EventTopicState.class); assertNotNull(result3); verifyMapSize(map, 3); Operation delete = Operation.createDelete(host, result1.documentSelfLink); result1 = sender.sendAndWait(delete, EventTopicState.class); assertNotNull(result1); verifyMapSize(map, 2); }
TestRequestSender sender = new TestRequestSender(host); List<ExampleServiceState> childStates = sender.sendAndWait(postOps, ExampleServiceState.class); ServiceDocumentQueryResult templateResult = sender.sendGetAndWait(uri, ServiceDocumentQueryResult.class);
@Test public void synchTaskStopsSelfPatchingOnFactoryDelete() throws Throwable { String factoryLink = ExampleService.FACTORY_LINK; this.host.createExampleServices(this.host, this.serviceCount, null, false, factoryLink); SynchronizationTaskService.State task = createSynchronizationTaskState(Long.MAX_VALUE, factoryLink); Operation op = Operation .createPost(UriUtils.buildUri(this.host, SynchronizationTaskService.FACTORY_LINK)) .setBody(task); TestRequestSender sender = new TestRequestSender(this.host); sender.sendRequest(Operation.createDelete(UriUtils.buildUri(this.host, factoryLink))); SynchronizationTaskService.State result = sender.sendAndWait(op, SynchronizationTaskService.State.class); // Verify that patch count stops incrementing after a while AtomicInteger previousValue = new AtomicInteger(); this.host.waitFor("Expected synch task to stop patching itself", () -> { // Get the latest patch count URI statsURI = UriUtils.buildStatsUri(this.host, result.documentSelfLink); ServiceStats stats = this.host.getServiceState(null, ServiceStats.class, statsURI); ServiceStats.ServiceStat synchRetryCount = stats.entries .get(STAT_NAME_PATCH_REQUEST_COUNT); return previousValue.getAndSet((int)synchRetryCount.latestValue) == synchRetryCount.latestValue; }); }
qt.querySpec.options.add(QueryOption.EXPAND_CONTENT); QueryTask activeTask = s.sendPostAndWait( UriUtils.buildUri(host.getUri(), ServiceUriPaths.CORE_LOCAL_QUERY_TASKS), qt, QueryTask.class); TestContext.waitFor(s.getTimeout(), () -> { QueryTask queryTaskResponse = s.sendGetAndWait(queryTaskURI, QueryTask.class); if (queryTaskResponse.results != null TestContext ctx = new TestContext(1, s.getTimeout()); Operation subscribe = Operation.createPost(queryTaskURI) .setReferer(host.getUri())
ExampleServiceState state = new ExampleServiceState(); state.name = this.host.nextUUID(); sender.sendRequest(Operation.createGet(u).setCompletion(ctx.getCompletion())); sender.sendRequest( Operation.createPatch(u) .setContextId(this.host.nextUUID()) ServiceStats after = sender.sendStatsGetAndWait(this.host.getManagementServiceUri()); for (URI u : states.keySet()) { String getStatName = u.getPath() + ":" + Action.GET; ExampleServiceState state = new ExampleServiceState(); state.name = this.host.nextUUID(); sender.sendRequest(Operation.createGet(u).setCompletion(ctx.getCompletion())); sender.sendRequest( Operation.createPatch(u).setContextId(this.host.nextUUID()).setBody(state) .setCompletion(ctx.getCompletion())); LogServiceState logsAfterFiner = sender.sendGetAndWait( UriUtils.buildUri(this.host, ServiceUriPaths.PROCESS_LOG), LogServiceState.class);
@Test public void testCreateAndGet() { ExtensibilitySubscription state = createExtensibilityState(); URI uri = UriUtils.buildUri(host, ExtensibilitySubscriptionService.FACTORY_LINK); ExtensibilitySubscription result = sender .sendPostAndWait(uri, state, ExtensibilitySubscription.class); assertNotNull(result); assertNotNull(result.documentSelfLink); assertEquals(state.task, result.task); assertEquals(state.stage, result.stage); assertEquals(state.substage, result.substage); uri = UriUtils.buildUri(host, result.documentSelfLink); result = sender.sendGetAndWait(uri, ExtensibilitySubscription.class); assertNotNull(result); }
/** * Synchronously perform GET to given url. * * Expecting GET to be successful. * * @param url URL * @param bodyType returned body type * @param <T> ServiceDocument * @return body document */ public <T extends ServiceDocument> T sendGetAndWait(String url, Class<T> bodyType) { return sendGetAndWait(URI.create(url), bodyType); }
waitContext.complete(); }); sendRequest(op);
public VerificationHost setTimeoutSeconds(int seconds) { this.timeoutSeconds = seconds; if (this.sender != null) { this.sender.setTimeout(Duration.ofSeconds(seconds)); } for (VerificationHost peer : this.localPeerHosts.values()) { peer.setTimeoutSeconds(seconds); } return this; }
/** * Synchronously perform POST to given url. * * Expecting POST to be successful. * * @param url URL * @param bodyType returned body type * @param <T> ServiceDocument * @return body document */ public <T extends ServiceDocument> T sendPostAndWait(String url, T body, Class<T> bodyType) { return sendPostAndWait(URI.create(url), body, bodyType); }
@Test public void testAddRemoveExtensibility() throws Throwable { ExtensibilitySubscription state1 = createExtensibilityState("substage1", "uri1"); ExtensibilitySubscription state2 = createExtensibilityState("substage2", "uri2"); ExtensibilitySubscription state3 = createExtensibilityState("substage3", "uri3"); Map<String, ExtensibilitySubscription> map = getExtensibilitySubscriptions(); assertNotNull(map); URI uri = UriUtils.buildUri(host, ExtensibilitySubscriptionService.FACTORY_LINK); ExtensibilitySubscription result1 = sender .sendPostAndWait(uri, state1, ExtensibilitySubscription.class); assertNotNull(result1); verifyMapSize(map, 1); ExtensibilitySubscription result2 = sender .sendPostAndWait(uri, state2, ExtensibilitySubscription.class); assertNotNull(result2); verifyMapSize(map, 2); ExtensibilitySubscription result3 = sender .sendPostAndWait(uri, state3, ExtensibilitySubscription.class); assertNotNull(result3); verifyMapSize(map, 3); Operation delete = Operation.createDelete(host, result1.documentSelfLink); result1 = sender.sendAndWait(delete, ExtensibilitySubscription.class); assertNotNull(result1); verifyMapSize(map, 2); }
TestRequestSender sender = new TestRequestSender(host); List<ExampleServiceState> childStates = sender.sendAndWait(postOps, ExampleServiceState.class); ServiceDocumentQueryResult templateResult = sender.sendGetAndWait(uri, ServiceDocumentQueryResult.class);
@Test public void synchTaskStopsSelfPatchingOnFactoryDelete() throws Throwable { String factoryLink = ExampleService.FACTORY_LINK; this.host.createExampleServices(this.host, this.serviceCount, null, false, factoryLink); SynchronizationTaskService.State task = createSynchronizationTaskState(Long.MAX_VALUE, factoryLink); Operation op = Operation .createPost(UriUtils.buildUri(this.host, SynchronizationTaskService.FACTORY_LINK)) .setBody(task); TestRequestSender sender = new TestRequestSender(this.host); sender.sendRequest(Operation.createDelete(UriUtils.buildUri(this.host, factoryLink))); SynchronizationTaskService.State result = sender.sendAndWait(op, SynchronizationTaskService.State.class); // Verify that patch count stops incrementing after a while AtomicInteger previousValue = new AtomicInteger(); this.host.waitFor("Expected synch task to stop patching itself", () -> { // Get the latest patch count URI statsURI = UriUtils.buildStatsUri(this.host, result.documentSelfLink); ServiceStats stats = this.host.getServiceState(null, ServiceStats.class, statsURI); ServiceStats.ServiceStat synchRetryCount = stats.entries .get(STAT_NAME_PATCH_REQUEST_COUNT); return previousValue.getAndSet((int)synchRetryCount.latestValue) == synchRetryCount.latestValue; }); }
@Test public void testAuthentication() throws Throwable { String headerVal = BasicAuthenticationUtils.constructBasicAuth(USER_JANE_EMAIL, USER_JANE_EMAIL); URI authServiceUri = UriUtils.buildUri(this.host, BasicAuthenticationService.SELF_LINK); TestRequestSender sender = new TestRequestSender(this.host); Operation returnOp = sender.sendAndWait((Operation .createPost(authServiceUri) .setBody(new Object()) .addRequestHeader(Operation.AUTHORIZATION_HEADER, headerVal))); assertTrue(returnOp.getStatusCode() == Operation.STATUS_CODE_OK); }
qt.querySpec.options.add(QueryOption.EXPAND_CONTENT); QueryTask activeTask = s.sendPostAndWait( UriUtils.buildUri(host.getUri(), ServiceUriPaths.CORE_LOCAL_QUERY_TASKS), qt, QueryTask.class); TestContext.waitFor(s.getTimeout(), () -> { QueryTask queryTaskResponse = s.sendGetAndWait(queryTaskURI, QueryTask.class); if (queryTaskResponse.results != null TestContext ctx = new TestContext(1, s.getTimeout()); Operation subscribe = Operation.createPost(queryTaskURI) .setReferer(host.getUri())
ExampleServiceState state = new ExampleServiceState(); state.name = this.host.nextUUID(); sender.sendRequest(Operation.createGet(u).setCompletion(ctx.getCompletion())); sender.sendRequest( Operation.createPatch(u) .setContextId(this.host.nextUUID()) ServiceStats after = sender.sendStatsGetAndWait(this.host.getManagementServiceUri()); for (URI u : states.keySet()) { String getStatName = u.getPath() + ":" + Action.GET; ExampleServiceState state = new ExampleServiceState(); state.name = this.host.nextUUID(); sender.sendRequest(Operation.createGet(u).setCompletion(ctx.getCompletion())); sender.sendRequest( Operation.createPatch(u).setContextId(this.host.nextUUID()).setBody(state) .setCompletion(ctx.getCompletion())); LogServiceState logsAfterFiner = sender.sendGetAndWait( UriUtils.buildUri(this.host, ServiceUriPaths.PROCESS_LOG), LogServiceState.class);