Search in sources :

Example 11 with ContainerPlacementResponseMessage

use of org.apache.samza.container.placement.ContainerPlacementResponseMessage in project samza by apache.

the class TestContainerPlacementMetadataStore method testContainerPlacementMessageDeletion.

@Test
public void testContainerPlacementMessageDeletion() {
    Long timestamp = System.currentTimeMillis();
    UUID requestMessage1UUID = containerPlacementMetadataStore.writeContainerPlacementRequestMessage("app-attempt-001", "4", "ANY_HOST", null, timestamp);
    UUID requestMessage2UUID = containerPlacementMetadataStore.writeContainerPlacementRequestMessage("app-attempt-001", "1", "host2", Duration.ofMillis(100), timestamp);
    ContainerPlacementResponseMessage responseMessage1 = new ContainerPlacementResponseMessage(requestMessage1UUID, "app-attempt-001", "4", "ANY_HOST", ContainerPlacementMessage.StatusCode.BAD_REQUEST, "Request ignored redundant", System.currentTimeMillis());
    ContainerPlacementResponseMessage responseMessage2 = new ContainerPlacementResponseMessage(requestMessage2UUID, "app-attempt-001", "1", "ANY_HOST", ContainerPlacementMessage.StatusCode.IN_PROGRESS, "Requested resources", System.currentTimeMillis());
    containerPlacementMetadataStore.writeContainerPlacementResponseMessage(responseMessage1);
    containerPlacementMetadataStore.writeContainerPlacementResponseMessage(responseMessage2);
    Assert.assertTrue(containerPlacementMetadataStore.readContainerPlacementRequestMessage(requestMessage1UUID).isPresent());
    Assert.assertTrue(containerPlacementMetadataStore.readContainerPlacementResponseMessage(requestMessage2UUID).isPresent());
    Assert.assertEquals(4, containerPlacementMetadataStore.getContainerPlacementStore().all().size());
    containerPlacementMetadataStore.deleteContainerPlacementResponseMessage(requestMessage1UUID);
    Assert.assertEquals(3, containerPlacementMetadataStore.getContainerPlacementStore().all().size());
    Assert.assertTrue(containerPlacementMetadataStore.readContainerPlacementRequestMessage(requestMessage1UUID).isPresent());
    containerPlacementMetadataStore.deleteContainerPlacementRequestMessage(requestMessage1UUID);
    Assert.assertEquals(2, containerPlacementMetadataStore.getContainerPlacementStore().all().size());
    assertContainerPlacementRequestMessage(requestMessage2UUID, "app-attempt-001", "1", "host2", Duration.ofMillis(100), timestamp, containerPlacementMetadataStore.readContainerPlacementRequestMessage(requestMessage2UUID).get());
    Assert.assertEquals(containerPlacementMetadataStore.readContainerPlacementResponseMessage(requestMessage2UUID).get(), responseMessage2);
    // requestMessage1 & associated responseMessage1 should not be present
    Assert.assertTrue(!containerPlacementMetadataStore.readContainerPlacementRequestMessage(requestMessage1UUID).isPresent());
    Assert.assertTrue(!containerPlacementMetadataStore.readContainerPlacementResponseMessage(requestMessage1UUID).isPresent());
    requestMessage1UUID = containerPlacementMetadataStore.writeContainerPlacementRequestMessage("app-attempt-001", "4", "ANY_HOST", null, System.currentTimeMillis());
    containerPlacementMetadataStore.writeContainerPlacementResponseMessage(responseMessage1);
    containerPlacementMetadataStore.deleteAllContainerPlacementMessages(requestMessage1UUID);
    // requestMessage1 & associated responseMessage1 should not be present
    Assert.assertTrue(!containerPlacementMetadataStore.readContainerPlacementRequestMessage(requestMessage1UUID).isPresent());
    Assert.assertTrue(!containerPlacementMetadataStore.readContainerPlacementResponseMessage(requestMessage1UUID).isPresent());
    containerPlacementMetadataStore.deleteAllContainerPlacementMessages();
    Assert.assertEquals(0, containerPlacementMetadataStore.readAllContainerPlacementRequestMessages().size());
}
Also used : UUID(java.util.UUID) ContainerPlacementResponseMessage(org.apache.samza.container.placement.ContainerPlacementResponseMessage) Test(org.junit.Test)

Example 12 with ContainerPlacementResponseMessage

use of org.apache.samza.container.placement.ContainerPlacementResponseMessage in project samza by apache.

the class TestContainerPlacementObjectMapper method testOutgoingContainerMessageSerDe.

@Test
public void testOutgoingContainerMessageSerDe() throws IOException {
    testContainerPlacementResponseMessage(new ContainerPlacementResponseMessage(UUID.randomUUID(), "app-attempt-001", Integer.toString(new Random().nextInt(5)), "ANY_HOST", ContainerPlacementMessage.StatusCode.BAD_REQUEST, "Request ignored redundant", System.currentTimeMillis()));
    testContainerPlacementResponseMessage(new ContainerPlacementResponseMessage(UUID.randomUUID(), "app-attempt-001", Integer.toString(new Random().nextInt(5)), "ANY_HOST", Duration.ofSeconds(10), ContainerPlacementMessage.StatusCode.IN_PROGRESS, "Request is in progress", System.currentTimeMillis()));
}
Also used : Random(java.util.Random) ContainerPlacementResponseMessage(org.apache.samza.container.placement.ContainerPlacementResponseMessage) Test(org.junit.Test)

Aggregations

ContainerPlacementResponseMessage (org.apache.samza.container.placement.ContainerPlacementResponseMessage)12 Test (org.junit.Test)9 ContainerPlacementRequestMessage (org.apache.samza.container.placement.ContainerPlacementRequestMessage)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 ContainerPlacementMetadata (org.apache.samza.clustermanager.container.placement.ContainerPlacementMetadata)5 UUID (java.util.UUID)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 Random (java.util.Random)2 ContainerPlacementRequestAllocator (org.apache.samza.clustermanager.container.placement.ContainerPlacementRequestAllocator)2 ApplicationConfig (org.apache.samza.config.ApplicationConfig)2 ContainerPlacementMessage (org.apache.samza.container.placement.ContainerPlacementMessage)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 SamzaException (org.apache.samza.SamzaException)1 ClusterManagerConfig (org.apache.samza.config.ClusterManagerConfig)1 MapConfig (org.apache.samza.config.MapConfig)1 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)1