FactoryService extends StatelessService { @Override public URI getUri() { if (this.uri == null) { this.uri = super.getUri(); } return this.uri; } FactoryService(Class<? extends ServiceDocument> childServiceDocumentType); static FactoryService create(Class<? extends Service> childServiceType,
            ServiceOption... options); static FactoryService create(Class<? extends Service> childServiceType,
            Class<? extends ServiceDocument> childServiceDocumentType, ServiceOption... options); static FactoryService createIdempotent(Class<? extends Service> childServiceType); static FactoryService createIdempotent(Class<? extends Service> childServiceType,
            Class<? extends ServiceDocument> childServiceDocumentType); void setSelfQueryResultLimit(int limit); int getSelfQueryResultLimit(); void setUseBodyForSelfLink(boolean useBody); boolean hasChildOption(ServiceOption option); @Override void handleStart(Operation startPost); @Override void authorizeRequest(Operation op); @Override void handleRequest(Operation op); @Override void handleRequest(Operation op, OperationProcessingStage opProcessingStage); @Override void handleStop(Operation op); @Override void handleGet(Operation get); void completeGetWithQuery(Operation op, EnumSet<ServiceOption> caps); @Override void handleOptions(Operation op); @Override void handlePost(Operation op); @Override void toggleOption(ServiceOption option, boolean enable); @Override String getPeerNodeSelectorPath(); @Override void setPeerNodeSelectorPath(String link); @Override URI getUri(); @Override ServiceDocument getDocumentTemplate(); @Override void handleConfigurationRequest(Operation request); @Override void handleNodeGroupMaintenance(Operation maintOp); abstract Service createServiceInstance(); static final int MAX_SYNCH_RETRY_COUNT; static final Integer SELF_QUERY_RESULT_LIMIT; }
@Test public void synchronizationTaskRetryOnFailure() throws Throwable { int testSynchRetryCount = 3; this.host.waitForNodeGroupConvergence(); this.host.waitForReplicatedFactoryServiceAvailable( UriUtils.buildUri(this.host, ExampleService.FACTORY_LINK), ServiceUriPaths.DEFAULT_NODE_SELECTOR); String synchTaskServicePath = UriUtils.buildUriPath( SynchronizationTaskService.FACTORY_LINK, UriUtils.convertPathCharsFromLink(ExampleService.FACTORY_LINK)); URI synchTaskServiceUri = UriUtils.buildUri(this.host.getUri(), synchTaskServicePath); this.host.sendAndWaitExpectSuccess(Operation .createDelete(synchTaskServiceUri) .setCompletion(this.host.getCompletion())); ControlledStateSynchTaskService.State state = new ControlledStateSynchTaskService.State(); state.taskInfo = new TaskState(); state.maxFailureCount = testSynchRetryCount; state.documentSelfLink = synchTaskServicePath; Operation post = Operation .createPost(this.host, synchTaskServicePath) .setBody(state); this.host.startService(post, new ControlledStateSynchTaskService()); this.host.waitForServiceAvailable(synchTaskServiceUri); this.host.scheduleNodeGroupChangeMaintenance(ServiceUriPaths.DEFAULT_NODE_SELECTOR); waitForSynchRetries(Service.STAT_NAME_SYNCH_TASK_RETRY_COUNT, (synchRetryCount) -> synchRetryCount.latestValue >= 1); waitForSynchRetries(Service.STAT_NAME_SYNCH_TASK_RETRY_COUNT, (synchRetryCount) -> synchRetryCount.latestValue == 0); state = new ControlledStateSynchTaskService.State(); state.maxFailureCount = Integer.MAX_VALUE; state.documentSelfLink = synchTaskServicePath; this.host.sendAndWaitExpectSuccess( Operation.createPatch(this.host, synchTaskServicePath) .setBody(state) .setCompletion(this.host.getCompletion())); this.host.scheduleNodeGroupChangeMaintenance(ServiceUriPaths.DEFAULT_NODE_SELECTOR); this.host.setMaintenanceIntervalMicros(TimeUnit.MILLISECONDS.toMicros(1)); waitForSynchRetries(Service.STAT_NAME_SYNCH_TASK_RETRY_COUNT, (synchRetryCount) -> synchRetryCount.latestValue >= FactoryService.MAX_SYNCH_RETRY_COUNT); waitForSynchRetries(Service.STAT_NAME_CHILD_SYNCH_FAILURE_COUNT, (synchFailureCount) -> synchFailureCount.latestValue >= 1); }
@Test public void factoryClonePostExpectFailure() throws Throwable { MinimalFactoryTestService f = new MinimalFactoryTestService(); MinimalFactoryTestService factoryService = (MinimalFactoryTestService) this.host .startServiceAndWait(f, UUID.randomUUID().toString(), null); this.host.waitForServiceAvailable(factoryService.getUri()); MinimalTestServiceState initState = (MinimalTestServiceState) this.host .buildMinimalTestState(); initState.documentSelfLink = UUID.randomUUID().toString(); this.host.testStart(1); this.host.send(Operation.createPost(factoryService.getUri()) .setBody(initState) .setCompletion(this.host.getCompletion())); this.host.testWait(); ServiceDocumentQueryResult rsp = this.host.getFactoryState(factoryService.getUri()); initState = new MinimalTestServiceState(); initState.documentSelfLink = UUID.randomUUID().toString(); initState.documentSourceLink = rsp.documentLinks.iterator().next(); this.host.testStart(1); this.host.send(Operation.createPost(factoryService.getUri()) .setBody(initState) .setCompletion(this.host.getExpectedFailureCompletion())); this.host.testWait(); }
@Test public void factoryDurableServicePostWithDeleteRestart() throws Throwable { long count = this.serviceCount; MinimalFactoryTestService f = new MinimalFactoryTestService(); f.setChildServiceCaps(EnumSet.of(ServiceOption.PERSISTENCE)); MinimalFactoryTestService factoryService = (MinimalFactoryTestService) this.host .startServiceAndWait(f, UUID.randomUUID().toString(), null); this.host.waitForServiceAvailable(factoryService.getUri()); doFactoryServiceChildCreation(EnumSet.of(ServiceOption.PERSISTENCE), EnumSet.of(TestProperty.DELETE_DURABLE_SERVICE), count, factoryService.getUri()); doFactoryServiceChildCreation(EnumSet.of(ServiceOption.PERSISTENCE), EnumSet.of(TestProperty.DELETE_DURABLE_SERVICE), count, factoryService.getUri()); f = new MinimalFactoryTestService(); EnumSet<ServiceOption> caps = EnumSet.of(ServiceOption.PERSISTENCE, ServiceOption.REPLICATION); f.setChildServiceCaps(caps); factoryService = (MinimalFactoryTestService) this.host .startServiceAndWait(f, UUID.randomUUID().toString(), null); doFactoryServiceChildCreation(caps, EnumSet.of(TestProperty.DELETE_DURABLE_SERVICE), count, factoryService.getUri()); doFactoryServiceChildCreation(caps, EnumSet.of(TestProperty.DELETE_DURABLE_SERVICE), count, factoryService.getUri()); }
@Test public void invalidSubChildPath() throws Throwable { MinimalFactoryTestService f = new MinimalFactoryTestService(); f.setChildServiceCaps(EnumSet.of(ServiceOption.PERSISTENCE)); f = (MinimalFactoryTestService) this.host .startServiceAndWait(f, UUID.randomUUID().toString(), null); this.host.waitForServiceAvailable(f.getUri()); MinimalTestServiceState initialState = (MinimalTestServiceState) this.host .buildMinimalTestState(); initialState.documentSelfLink = "foo"; Operation post = Operation .createPost(f.getUri()) .setBody(initialState); this.host.sendAndWaitExpectSuccess(post); Operation get = Operation .createGet(UriUtils.extendUri(f.getUri(), initialState.documentSelfLink)); this.host.sendAndWaitExpectSuccess(get); TestRequestSender sender = this.host.getTestRequestSender(); get = Operation .createGet(UriUtils.extendUri(f.getUri(), initialState.documentSelfLink + "/sub-child")); sender.sendAndWaitFailure(get); }
@Test public void factoryServiceRemotePost() throws Throwable { long count = 100; URI factoryUri = this.host.startServiceAndWait( MinimalFactoryTestService.class, UUID.randomUUID().toString()) .getUri(); EnumSet<TestProperty> props = EnumSet.of(TestProperty.FORCE_REMOTE); doFactoryServiceChildCreation(props, count, factoryUri); }
@Test public void throughputFactoryServicePost() throws Throwable { long count = this.serviceCount; if (count < 1) { count = this.host.computeIterationsFromMemory(10) / 20; } URI factoryUri = this.host.startServiceAndWait( MinimalFactoryTestService.class, UUID.randomUUID().toString()) .getUri(); doFactoryServiceChildCreation(count, factoryUri); doFactoryServiceChildCreation(count, factoryUri); }
@Test public void duplicateFactoryPostWithInitialFailure() throws Throwable { MinimalFactoryTestService factory = (MinimalFactoryTestService) this.host .startServiceAndWait( MinimalFactoryTestService.class, UUID.randomUUID().toString()); URI factoryUri = factory.getUri(); String selfLink = UUID.randomUUID().toString(); this.host.testStart(1); MinimalTestServiceState initialState = (MinimalTestServiceState) this.host .buildMinimalTestState(); initialState.id = null; initialState.documentSelfLink = selfLink; Operation post = Operation .createPost(factoryUri) .setBody(initialState) .setCompletion(this.host.getExpectedFailureCompletion()); this.host.send(post); this.host.testWait(); this.host.testStart(1); this.host.send(Operation.createGet(UriUtils.extendUri(factoryUri, selfLink)).setCompletion( this.host.getExpectedFailureCompletion())); this.host.testWait(); this.host.testStart(1); initialState = (MinimalTestServiceState) this.host.buildMinimalTestState(); initialState.documentSelfLink = selfLink; post.setBody(initialState).setCompletion(this.host.getCompletion()); this.host.send(post); this.host.testWait(); }