/** * 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 State waitForServiceCompletion(TestRequestSender sender, URI taskUri) { Set<TaskStage> finalStages = EnumSet.of(TaskStage.CANCELLED, TaskStage.FAILED, TaskStage.FINISHED); Duration waitDuration = Duration.ofSeconds(this.taskWaitSeconds); AtomicReference<State> stateHolder = new AtomicReference<>(); TestContext.waitFor(waitDuration, () -> { State state = sender.sendAndWait(Operation.createGet(taskUri), State.class); stateHolder.set(state); return finalStages.contains(state.taskInfo.stage); }, () -> "Timeout while waiting migration task to finish"); return stateHolder.get(); }
private List<NodeGroupState> getNodeGroupStates() { TestRequestSender sender = getTestRequestSender(); String nodeGroupPath = getNodeGroupPath(); List<Operation> nodeGroupOps = this.hosts.stream() .map(host -> UriUtils.buildUri(host.getUri(), nodeGroupPath)) .map(Operation::createGet) .collect(toList()); return sender.sendAndWait(nodeGroupOps, NodeGroupState.class); }
private List<ExampleServiceState> createImmutableDocuments(VerificationHost targetHost, long numOfDocs) { List<Operation> ops = new ArrayList<>(); for (int i = 0; i < numOfDocs; i++) { ExampleServiceState state = new ExampleService.ExampleServiceState(); state.name = "doc-" + i; state.documentSelfLink = state.name; state.counter = (long) i; Operation post = Operation.createPost(targetHost, ImmutableExampleService.FACTORY_LINK).setBody(state); ops.add(post); } return this.sender.sendAndWait(ops, ExampleServiceState.class); }
private List<ExampleServiceState> createImmutableDocuments(VerificationHost targetHost, long numOfDocs) { List<Operation> ops = new ArrayList<>(); for (int i = 0; i < numOfDocs; i++) { ExampleServiceState state = new ExampleService.ExampleServiceState(); state.name = "doc-" + i; state.documentSelfLink = state.name; state.counter = (long) i; Operation post = Operation.createPost(targetHost, ImmutableExampleService.FACTORY_LINK).setBody(state); ops.add(post); } return this.sender.sendAndWait(ops, ExampleServiceState.class); }
public void doServiceUpdates(Collection<URI> serviceUris, Action action, ServiceDocument body) { List<Operation> ops = new ArrayList<>(); for (URI u : serviceUris) { Operation update = Operation.createPost(u) .setAction(action) .setBody(body); ops.add(update); } this.sender.sendAndWait(ops); }
private List<ExampleServiceState> populateData(String factoryLink) { List<Operation> ops = new ArrayList<>(); for (int i = 0; i < this.count; i++) { ExampleServiceState state = new ExampleServiceState(); state.name = "foo-" + i; state.documentSelfLink = state.name; Operation post = Operation.createPost(this.host, factoryLink).setBody(state); ops.add(post); } return this.host.getTestRequestSender().sendAndWait(ops, ExampleServiceState.class); }
private List<ExampleService.ExampleServiceState> getExampleServices(List<ExampleService.ExampleServiceState> exampleStates) { List<Operation> ops = new ArrayList<>(); for (ExampleService.ExampleServiceState st : exampleStates) { URI serviceUri = UriUtils.buildUri(this.host.getPeerHost(), st.documentSelfLink); Operation get = Operation.createGet(serviceUri); ops.add(get); } return this.host.getTestRequestSender().sendAndWait(ops, ExampleService.ExampleServiceState.class); }
public void setNodeGroupConfig(NodeGroupConfig config) { setSystemAuthorizationContext(); List<Operation> ops = new ArrayList<>(); for (URI nodeGroup : getNodeGroupMap().values()) { NodeGroupState body = new NodeGroupState(); body.config = config; body.nodes = null; ops.add(Operation.createPatch(nodeGroup).setBody(body)); } this.sender.sendAndWait(ops); resetAuthorizationContext(); }
public void setNodeGroupConfig(NodeGroupConfig config) { setSystemAuthorizationContext(); List<Operation> ops = new ArrayList<>(); for (URI nodeGroup : getNodeGroupMap().values()) { NodeGroupState body = new NodeGroupState(); body.config = config; body.nodes = null; ops.add(Operation.createPatch(nodeGroup).setBody(body)); } this.sender.sendAndWait(ops); resetAuthorizationContext(); }
public void setServiceMaintenanceIntervalMicros(URI u, long micros) { ServiceConfigUpdateRequest updateBody = ServiceConfigUpdateRequest.create(); updateBody.maintenanceIntervalMicros = micros; URI configUri = UriUtils.extendUri(u, ServiceHost.SERVICE_URI_SUFFIX_CONFIG); this.sender.sendAndWait(Operation.createPatch(configUri).setBody(updateBody)); }
private void setRequestLogging(VerificationHost newHost, boolean enabled) { ServiceHost.RequestLoggingInfo loggingInfo = new ServiceHost.RequestLoggingInfo(); loggingInfo.enabled = enabled; ServiceHostManagementService.ConfigureInboundRequestLogging request = new ServiceHostManagementService.ConfigureInboundRequestLogging(); request.kind = ServiceHostManagementService.ConfigureInboundRequestLogging.KIND; request.loggingInfo = loggingInfo; this.host.getTestRequestSender().sendAndWait(Operation.createPatch( newHost, ServiceUriPaths.CORE_MANAGEMENT).setBody(request)); }
private void setRequestLogging(VerificationHost newHost, boolean enabled) { ServiceHost.RequestLoggingInfo loggingInfo = new ServiceHost.RequestLoggingInfo(); loggingInfo.enabled = enabled; ServiceHostManagementService.ConfigureInboundRequestLogging request = new ServiceHostManagementService.ConfigureInboundRequestLogging(); request.kind = ServiceHostManagementService.ConfigureInboundRequestLogging.KIND; request.loggingInfo = loggingInfo; this.host.getTestRequestSender().sendAndWait(Operation.createPatch( newHost, ServiceUriPaths.CORE_MANAGEMENT).setBody(request)); }
@Test public void testFactoryPostAndDelete() { UserState state = new UserState(); state.email = "jane@doe.com"; Operation op = Operation.createPost(this.host, ServiceUriPaths.CORE_AUTHZ_USERS).setBody(state); UserState outState = this.sender.sendAndWait(op, UserState.class); assertEquals(state.email, outState.email); }
public void setNodeGroupQuorum(Integer quorum, Integer locationQuorum, URI nodeGroup) { UpdateQuorumRequest body = UpdateQuorumRequest.create(true); if (quorum != null) { body.setMembershipQuorum(quorum); } if (locationQuorum != null) { body.setLocationQuorum(locationQuorum); } this.sender.sendAndWait(Operation.createPatch(nodeGroup).setBody(body)); }
@Test public void testGetEmpty() throws InterruptedException { ServiceDocumentQueryResult result = sender.sendAndWait( Operation.createGet(host, ExtensibilitySubscriptionService.FACTORY_LINK), ServiceDocumentQueryResult.class); assertNotNull(result); assertNotNull(result.documentCount); assertEquals(0L, (long) result.documentCount); }
public <T extends ServiceDocument> T verifyPost(Class<T> documentType, String factoryLink, T state, int expectedStatusCode) { URI uri = UriUtils.buildUri(this, factoryLink); Operation op = Operation.createPost(uri).setBody(state); Operation response = this.sender.sendAndWait(op); String message = String.format("Status code expected: %s, actual: %s", expectedStatusCode, response.getStatusCode()); assertEquals(message, expectedStatusCode, response.getStatusCode()); return response.hasBody() ? response.getBody(documentType) : null; }
private Endpoint createEndpoint(Endpoint endpoint) { Operation o = Operation .createPost(host, PKSEndpointFactoryService.SELF_LINK) .setBodyNoCloning(endpoint); Endpoint result = sender.sendAndWait(o, Endpoint.class); assertNotNull(result); assertNotNull(result.documentSelfLink); assertEquals(endpoint.uaaEndpoint, result.uaaEndpoint); assertEquals(endpoint.apiEndpoint, result.apiEndpoint); return result; }
private void checkDerivedSelfLinkWhenProvidedSelfLinkIsJustASuffix(TestRequestSender sender) throws Throwable { SomeDocument doc = new SomeDocument(); doc.documentSelfLink = "freddy-x1"; Operation o = sender.sendAndWait(Operation.createPost(this.factoryUri) .setBody(doc)); String selfLink = o.getBody(SomeDocument.class).documentSelfLink; URI opUri = o.getUri(); String expectedPath = "/subpath/fff/freddy-x1"; assertEquals(expectedPath, selfLink); assertEquals(UriUtils.buildUri(this.host, expectedPath), opUri); }
@Test public void failOnDestinationNodeFailureBeforeIssuingQuery() throws Throwable { createExampleDocuments(this.exampleSourceFactory, getSourceHost(), this.serviceCount); LegacyMigrationTaskService.State migrationState = validMigrationState(ExampleService.FACTORY_LINK); migrationState.sourceNodeGroupReference = UriUtils.extendUri(getSourceHost().getPublicUri(), ServiceUriPaths.DEFAULT_NODE_GROUP); migrationState.destinationNodeGroupReference = FAKE_URI; Operation op = Operation.createPost(this.destinationFactoryUri).setBody(migrationState); State state = this.sender.sendAndWait(op, State.class); State waitForServiceCompletion = waitForServiceCompletion(state.documentSelfLink, getDestinationHost()); assertEquals(TaskStage.FAILED, waitForServiceCompletion.taskInfo.stage); }