Java Code Examples for io.vlingo.symbio.Metadata#with()

The following examples show how to use io.vlingo.symbio.Metadata#with() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InMemoryStateStoreTest.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatStateStoreWritesAndReadsMetadataOperation() {
  final AccessSafely access1 = interest.afterCompleting(2);
  dispatcher.afterCompleting(2);

  final Entity1 entity = new Entity1("123", 5);
  final Metadata sourceMetadata = Metadata.with("value", "operation");

  store.write(entity.id, entity, 1, sourceMetadata, interest);
  store.read(entity.id, Entity1.class, interest);

  assertEquals(1, (int) access1.readFrom("readObjectResultedIn"));
  assertEquals(1, (int) access1.readFrom("writeObjectResultedIn"));
  assertEquals(Result.Success, access1.readFrom("objectReadResult"));
  assertEquals(entity, access1.readFrom("objectState"));
  final Metadata metadata = access1.readFrom("metadataHolder");
  assertNotNull(metadata);
  assertTrue(metadata.hasOperation());
  assertEquals("operation", metadata.operation);

  final Entity1 readEntity = (Entity1) access1.readFrom("objectState");

  assertEquals("123", readEntity.id);
  assertEquals(5, readEntity.value);
}
 
Example 2
Source File: ProjectableTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatStateDoesNotFail() {
  final Object object = new Object();
  final Projectable projectable =
          new TextProjectable(
                  new TextState("ABC", String.class, 1, "state", 1, Metadata.with(object, "value", "op1")),
                  Arrays.asList(),
                  "123");

  Assert.assertEquals(1, projectable.dataVersion());
  Assert.assertEquals("ABC", projectable.dataId());
  Assert.assertEquals("value", projectable.metadata());
  Assert.assertTrue(projectable.hasObject());
  Assert.assertNotNull(projectable.object());
  Assert.assertEquals(object, projectable.object());
  Assert.assertTrue(projectable.optionalObject().isPresent());
  Assert.assertTrue(projectable.hasState());
  Assert.assertEquals(1, projectable.typeVersion());
}
 
Example 3
Source File: TextProjectableTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testProjectableness() {
  final String textState = "test-state";
  final TextState state =
          new TextState("123", String.class, 1, textState, 1, Metadata.with("value", "op"));
  final Projectable projectable = new TextProjectable(state, Collections.emptyList(), "p123");

  assertEquals("op", projectable.becauseOf()[0]);
  assertEquals(textState, projectable.dataAsText());
  assertEquals("123", projectable.dataId());
  assertEquals(1, projectable.dataVersion());
  assertEquals("value", projectable.metadata());
  assertEquals("p123", projectable.projectionId());
  assertEquals(String.class.getName(), projectable.type());
  assertEquals(1, projectable.typeVersion());
}
 
Example 4
Source File: TextProjectableTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testStateWithEventProjectableness() {
  final String textState = "test-state";
  final TextState state =
          new TextState("123", String.class, 1, textState, 1, Metadata.with("value", "op"));
  final Entry<String> entry = new TextEntry();
  final Projectable projectable = new TextProjectable(state, Arrays.asList(entry), "p123");

  assertEquals("op", projectable.becauseOf()[0]);
  assertEquals("java.lang.Object", projectable.becauseOf()[1]);
  assertEquals(textState, projectable.dataAsText());
  assertEquals("123", projectable.dataId());
  assertEquals(1, projectable.dataVersion());
  assertEquals("value", projectable.metadata());
  assertEquals("p123", projectable.projectionId());
  assertEquals(String.class.getName(), projectable.type());
  assertEquals(1, projectable.typeVersion());
}
 
Example 5
Source File: BinaryProjectableTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testProjectableness() {
  final String textState = "test-state";
  final BinaryState state =
          new BinaryState("123", String.class, 1, textState.getBytes(), 1, Metadata.with("value", "op"));
  final Projectable projectable = new BinaryProjectable(state, Collections.emptyList(), "p123");

  assertEquals("op", projectable.becauseOf()[0]);
  assertArrayEquals(textState.getBytes(), projectable.dataAsBytes());
  assertEquals("123", projectable.dataId());
  assertEquals(1, projectable.dataVersion());
  assertEquals("value", projectable.metadata());
  assertEquals("p123", projectable.projectionId());
  assertEquals(String.class.getName(), projectable.type());
  assertEquals(1, projectable.typeVersion());
}
 
Example 6
Source File: StateProjectionDispatcherTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatDescribedProjectionsRegister() {
  final ProjectToDescription description = new ProjectToDescription(DescribedProjection.class, "op1", "op2");

  final Dispatcher dispatcher =
          world.actorFor(Dispatcher.class, TextProjectionDispatcherActor.class, Collections.singletonList(description));

  final Outcome outcome = new Outcome(2);
  final AccessSafely accessOutcome = outcome.afterCompleting(2);
  dispatcher.controlWith(outcome);

  final TextState state = new TextState("123", Object.class, 1, "blah1", 1, Metadata.with("", "op1"));
  dispatcher.dispatch(new Dispatchable<>("123", LocalDateTime.now(), state, Collections.emptyList()));

  final TextState state2 = new TextState("1235", Object.class, 1, "blah2", 1, Metadata.with("", "op2"));
  dispatcher.dispatch(new Dispatchable<>("1235", LocalDateTime.now(), state2, Collections.emptyList()));

  assertEquals(2, (int) accessOutcome.readFrom("count"));
}
 
Example 7
Source File: TextProjectableTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@Test(expected = UnsupportedOperationException.class)
public void testProjectableNotBytes() {
  final String textState = "test-state";
  final TextState state =
          new TextState("123", String.class, 1, textState, 1, Metadata.with("value", "op"));
  final Projectable projectable = new TextProjectable(state, Collections.emptyList(), "p123");
  projectable.dataAsBytes();
}
 
Example 8
Source File: BinaryProjectableTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@Test(expected = UnsupportedOperationException.class)
public void testProjectableNotText() {
  final String textState = "test-state";
  final BinaryState state =
          new BinaryState("123", String.class, 1, textState.getBytes(), 1, Metadata.with("value", "op"));
  final Projectable projectable = new BinaryProjectable(state, Collections.emptyList(), "p123");
  projectable.dataAsText();
}
 
Example 9
Source File: StatefulEntity.java    From vlingo-lattice with Mozilla Public License 2.0 3 votes vote down vote up
/**
 * Answer {@code Completes<RT>}, applying my current {@code state} and {@code metadataValue}
 * that was modified due to the descriptive {@code operation}, along with {@code sources}, and
 * supply an eventual outcome by means of the given {@code andThen} function.
 * @param state the S typed state to apply
 * @param sources the {@code List<Source>} instances to apply
 * @param metadataValue the String metadata value to apply along with the state
 * @param operation the String descriptive name of the operation that caused the state modification
 * @param andThen the {@code Supplier<RT>} that will provide the fully updated state following this operation,
 * and which will used to answer an eventual outcome to the client of this entity
 * @param <C> the type of Source
 * @param <RT> the return type of the Supplier function, which is the type of the completed state
 * @return {@code Completes<RT>}
 */
protected <C,RT> Completes<RT> apply(final S state, final List<Source<C>> sources, final String metadataValue, final String operation, final Supplier<RT> andThen) {
  final Metadata metadata = Metadata.with(state, metadataValue == null ? "" : metadataValue, operation == null ? "" : operation);
  stowMessages(WriteResultInterest.class);
  info.store.write(id, state, nextVersion(), sources, metadata, writeInterest, CompletionSupplier.supplierOrNull(andThen, completesEventually()));
  return andThen == null ? null : completes();
}
 
Example 10
Source File: StatefulEntity.java    From vlingo-lattice with Mozilla Public License 2.0 3 votes vote down vote up
/**
 * Answer {@code Completes<RT>}, applying my current {@code state} and {@code metadataValye}
 * that was modifieddue to the descriptive {@code operation} and supply an eventual outcome
 * by means of the given {@code andThen} function.
 * @param state the S typed state to apply
 * @param metadataValue the String metadata value to apply along with the state
 * @param operation the String descriptive name of the operation that caused the state modification
 * @param andThen the {@code Supplier<RT>} that will provide the fully updated state following this operation,
 * and which will used to answer an eventual outcome to the client of this entity
 * @param <RT> the return type of the Supplier function, which is the type of the completed state
 * @return {@code Completes<RT>}
 */
protected <RT> Completes<RT> apply(final S state, final String metadataValue, final String operation, final Supplier<RT> andThen) {
  final Metadata metadata = Metadata.with(state, metadataValue == null ? "" : metadataValue, operation == null ? "" : operation);
  stowMessages(WriteResultInterest.class);
  info.store.write(id, state, nextVersion(), metadata, writeInterest, CompletionSupplier.supplierOrNull(andThen, completesEventually()));
  return andThen == null ? null : completes();
}