ElementInstanceState { public ElementInstance newInstance( final long key, final WorkflowInstanceRecord value, final WorkflowInstanceIntent state) { return newInstance(null, key, value, state); } ElementInstanceState(
      final ZeebeDb<ZbColumnFamilies> zeebeDb,
      final DbContext dbContext,
      final KeyGenerator keyGenerator); ElementInstance newInstance(
      final long key, final WorkflowInstanceRecord value, final WorkflowInstanceIntent state); ElementInstance newInstance(
      final ElementInstance parent,
      final long key,
      final WorkflowInstanceRecord value,
      final WorkflowInstanceIntent state); ElementInstance getInstance(final long key); void removeInstance(final long key); StoredRecord getStoredRecord(final long recordKey); void updateInstance(final ElementInstance scopeInstance); List<ElementInstance> getChildren(final long parentKey); void consumeToken(final long scopeKey); void spawnToken(final long scopeKey); void storeRecord(
      final long key,
      final long scopeKey,
      final WorkflowInstanceRecord value,
      final WorkflowInstanceIntent intent,
      final Purpose purpose); void removeStoredRecord(final long scopeKey, final long recordKey, final Purpose purpose); List<IndexedRecord> getDeferredRecords(final long scopeKey); IndexedRecord getFailedRecord(final long key); VariablesState getVariablesState(); void setAwaitResultRequestMetadata(
      final long workflowInstanceKey, final AwaitWorkflowInstanceResultMetadata metadata); AwaitWorkflowInstanceResultMetadata getAwaitResultRequestMetadata(
      final long workflowInstanceKey);  }
@Test public void shouldCreateNewInstance() { final WorkflowInstanceRecord workflowInstanceRecord = createWorkflowInstanceRecord(); final ElementInstance elementInstance = elementInstanceState.newInstance( 100, workflowInstanceRecord, WorkflowInstanceIntent.ELEMENT_ACTIVATED); assertElementInstance(elementInstance, 0); }
@Test public void shouldCreateNewInstanceWithParent() { final WorkflowInstanceRecord workflowInstanceRecord = createWorkflowInstanceRecord(); final ElementInstance parentInstance = elementInstanceState.newInstance( 100, workflowInstanceRecord, WorkflowInstanceIntent.ELEMENT_ACTIVATED); final WorkflowInstanceRecord otherRecord = createWorkflowInstanceRecord(); otherRecord.setElementId("subProcess"); final ElementInstance childInstance = elementInstanceState.newInstance( parentInstance, 101, otherRecord, WorkflowInstanceIntent.ELEMENT_ACTIVATING); assertElementInstance(parentInstance, 1); assertChildInstance(childInstance, 101, "subProcess"); }