DatastoreStorage implements Closeable { WorkflowInstance writeActiveState(WorkflowInstance workflowInstance, RunState state) throws IOException { return runInTransactionWithRetries(tx -> tx.writeActiveState(workflowInstance, state)); } DatastoreStorage(CheckedDatastore datastore); @VisibleForTesting  DatastoreStorage(CheckedDatastore datastore,
                   Function<CheckedDatastoreTransaction, DatastoreStorageTransaction> storageTransactionFactory,
                   ExecutorService executor, Logger log); @Override void close(); void updateNextNaturalTrigger(WorkflowId workflowId, TriggerInstantSpec triggerSpec); Map<WorkflowId, Workflow> workflows(); Map<WorkflowId, Workflow> workflows(Set<WorkflowId> workflowIds); List<Workflow> workflows(String componentId); T runInTransactionWithRetries(TransactionFunction<T, E> f);  }
@Test public void shouldWriteActiveWorkflowInstanceWithState() throws Exception { storage.writeActiveState(WORKFLOW_INSTANCE, RUN_STATE1); List<Entity> activeInstances = entitiesOfKind(DatastoreStorage.KIND_ACTIVE_WORKFLOW_INSTANCE); assertThat(activeInstances, hasSize(1)); Entity instance = activeInstances.get(0); assertThat(instance.getLong(DatastoreStorage.PROPERTY_COUNTER), is(RUN_STATE1.counter())); assertThat(instance.getString(DatastoreStorage.PROPERTY_COMPONENT), is(WORKFLOW_INSTANCE.workflowId().componentId())); assertThat(instance.getString(DatastoreStorage.PROPERTY_WORKFLOW), is(WORKFLOW_INSTANCE.workflowId().id())); assertThat(instance.getString(DatastoreStorage.PROPERTY_PARAMETER), is(WORKFLOW_INSTANCE.parameter())); }
@Test public void shouldWriteActiveStatesWithSamePartitionAsSeparateEntities() throws Exception { storage.writeActiveState(WORKFLOW_INSTANCE1, RUN_STATE); storage.writeActiveState(WORKFLOW_INSTANCE2, RUN_STATE2); assertThat(entitiesOfKind(DatastoreStorage.KIND_ACTIVE_WORKFLOW_INSTANCE), hasSize(2)); }