use of org.apache.samza.container.placement.ContainerPlacementRequestMessage in project samza by apache.
the class TestContainerPlacementMetadataStore method testReadWriteContainerPlacementResponseMessages.
@Test
public void testReadWriteContainerPlacementResponseMessages() {
ContainerPlacementResponseMessage messageWrittenToMetastore = new ContainerPlacementResponseMessage(UUID.randomUUID(), "app-attempt-001", Integer.toString(new Random().nextInt(5)), "ANY_HOST", ContainerPlacementMessage.StatusCode.BAD_REQUEST, "Request ignored redundant", System.currentTimeMillis());
containerPlacementMetadataStore.writeContainerPlacementResponseMessage(messageWrittenToMetastore);
Optional<ContainerPlacementResponseMessage> messageReadFromMetastore = containerPlacementMetadataStore.readContainerPlacementResponseMessage(messageWrittenToMetastore.getUuid());
Assert.assertTrue(messageReadFromMetastore.isPresent());
Assert.assertEquals(messageWrittenToMetastore, messageReadFromMetastore.get());
// Request store must not contain anything
Optional<ContainerPlacementRequestMessage> readNull = containerPlacementMetadataStore.readContainerPlacementRequestMessage(messageWrittenToMetastore.getUuid());
Assert.assertTrue(!readNull.isPresent());
// No request messages should exist
Assert.assertTrue(!containerPlacementMetadataStore.readContainerPlacementRequestMessage(messageWrittenToMetastore.getUuid()).isPresent());
Assert.assertTrue(containerPlacementMetadataStore.getContainerPlacementStore().all().size() == 1);
}
use of org.apache.samza.container.placement.ContainerPlacementRequestMessage in project samza by apache.
the class TestContainerPlacementMetadataStore method testReadWriteContainerPlacementRequestMessages.
@Test
public void testReadWriteContainerPlacementRequestMessages() {
Long timestamp = System.currentTimeMillis();
UUID uuid = containerPlacementMetadataStore.writeContainerPlacementRequestMessage("app-attempt-001", "4", "ANY_HOST", null, timestamp);
Optional<ContainerPlacementRequestMessage> messageReadFromMetastore = containerPlacementMetadataStore.readContainerPlacementRequestMessage(uuid);
Assert.assertTrue(messageReadFromMetastore.isPresent());
assertContainerPlacementRequestMessage(uuid, "app-attempt-001", "4", "ANY_HOST", null, timestamp, messageReadFromMetastore.get());
// Check for non existent key
Optional<ContainerPlacementRequestMessage> readNull = containerPlacementMetadataStore.readContainerPlacementRequestMessage(UUID.randomUUID());
Assert.assertTrue(!readNull.isPresent());
// No response messages should exist
Assert.assertTrue(!containerPlacementMetadataStore.readContainerPlacementResponseMessage(uuid).isPresent());
Assert.assertEquals(1, containerPlacementMetadataStore.readAllContainerPlacementRequestMessages().size());
}
use of org.apache.samza.container.placement.ContainerPlacementRequestMessage in project samza by apache.
the class TestContainerPlacementObjectMapper method testIncomingContainerMessageSerDe.
@Test
public void testIncomingContainerMessageSerDe() throws IOException {
testContainerPlacementRequestMessage(new ContainerPlacementRequestMessage(UUID.randomUUID(), "app-attempt-001", "4", "ANY_HOST", System.currentTimeMillis()));
testContainerPlacementRequestMessage(new ContainerPlacementRequestMessage(UUID.randomUUID(), "app-attempt-001", "4", "ANY_HOST", Duration.ofSeconds(10), System.currentTimeMillis()));
}
use of org.apache.samza.container.placement.ContainerPlacementRequestMessage in project samza by apache.
the class ContainerPlacementMetadataStore method readContainerPlacementRequestMessage.
/**
* Reads a {@link ContainerPlacementRequestMessage} from the underlying metastore
* @param uuid uuid of the request
* @return ContainerPlacementRequestMessage if present
*/
public Optional<ContainerPlacementRequestMessage> readContainerPlacementRequestMessage(UUID uuid) {
Preconditions.checkState(!stopped, "Underlying metadata store not available");
Preconditions.checkNotNull(uuid, "uuid cannot be null");
byte[] messageBytes = containerPlacementMessageStore.get(toContainerPlacementMessageKey(uuid, ContainerPlacementRequestMessage.class));
if (ArrayUtils.isNotEmpty(messageBytes)) {
try {
ContainerPlacementRequestMessage requestMessage = (ContainerPlacementRequestMessage) objectMapper.readValue(messageBytes, ContainerPlacementMessage.class);
return Optional.of(requestMessage);
} catch (IOException e) {
throw new SamzaException(String.format("Error reading the ContainerPlacementResponseMessage for uuid: %s", uuid), e);
}
}
return Optional.empty();
}
Aggregations