Search in sources :

Example 11 with Partition

use of org.apache.samza.Partition in project samza by apache.

the class TestTaskCallbackManager method testUpdateCallbackInOrder.

@Test
public void testUpdateCallbackInOrder() {
    TaskName taskName = new TaskName("Partition 0");
    SystemStreamPartition ssp = new SystemStreamPartition("kafka", "topic", new Partition(0));
    ReadableCoordinator coordinator = new ReadableCoordinator(taskName);
    IncomingMessageEnvelope envelope0 = new IncomingMessageEnvelope(ssp, "0", null, null);
    TaskCallbackImpl callback0 = new TaskCallbackImpl(listener, taskName, envelope0, coordinator, 0, 0);
    List<TaskCallbackImpl> callbacksToUpdate = callbackManager.updateCallback(callback0);
    assertEquals(1, callbacksToUpdate.size());
    TaskCallbackImpl callback = callbacksToUpdate.get(0);
    assertTrue(callback.matchSeqNum(0));
    assertEquals(ssp, callback.envelope.getSystemStreamPartition());
    assertEquals("0", callback.envelope.getOffset());
    IncomingMessageEnvelope envelope1 = new IncomingMessageEnvelope(ssp, "1", null, null);
    TaskCallbackImpl callback1 = new TaskCallbackImpl(listener, taskName, envelope1, coordinator, 1, 0);
    callbacksToUpdate = callbackManager.updateCallback(callback1);
    assertEquals(1, callbacksToUpdate.size());
    callback = callbacksToUpdate.get(0);
    assertTrue(callback.matchSeqNum(1));
    assertEquals(ssp, callback.envelope.getSystemStreamPartition());
    assertEquals("1", callback.envelope.getOffset());
}
Also used : Partition(org.apache.samza.Partition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) TaskName(org.apache.samza.container.TaskName) IncomingMessageEnvelope(org.apache.samza.system.IncomingMessageEnvelope) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Test(org.junit.Test)

Example 12 with Partition

use of org.apache.samza.Partition in project samza by apache.

the class HdfsSystemConsumer method getPartitionDescriptor.

private List<String> getPartitionDescriptor(SystemStreamPartition systemStreamPartition) {
    String streamName = systemStreamPartition.getStream();
    Partition partition = systemStreamPartition.getPartition();
    try {
        return cachedPartitionDescriptorMap.get(streamName).get(partition);
    } catch (ExecutionException e) {
        throw new SamzaException("Failed to obtain descriptor for " + systemStreamPartition, e);
    }
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) ExecutionException(java.util.concurrent.ExecutionException) SamzaException(org.apache.samza.SamzaException)

Example 13 with Partition

use of org.apache.samza.Partition in project samza by apache.

the class TestPartitionDesctiptorUtil method testBasicEncodeDecode.

@Test
public void testBasicEncodeDecode() {
    Map<Partition, List<String>> input = new HashMap<>();
    input.put(new Partition(0), Collections.singletonList("path_0"));
    String[] array = { "path_1", "path_2" };
    input.put(new Partition(1), Arrays.asList(array));
    input.put(new Partition(3), Collections.singletonList("path_3"));
    String json = PartitionDescriptorUtil.getJsonFromDescriptorMap(input);
    Map<Partition, List<String>> output = PartitionDescriptorUtil.getDescriptorMapFromJson(json);
    Assert.assertEquals(3, output.entrySet().size());
    Assert.assertTrue(output.containsKey(new Partition(0)));
    Assert.assertEquals("path_0", output.get(new Partition(0)).get(0));
    Assert.assertTrue(output.containsKey(new Partition(1)));
    Assert.assertEquals("path_1", output.get(new Partition(1)).get(0));
    Assert.assertEquals("path_2", output.get(new Partition(1)).get(1));
    Assert.assertTrue(output.containsKey(new Partition(3)));
    Assert.assertEquals("path_3", output.get(new Partition(3)).get(0));
}
Also used : Partition(org.apache.samza.Partition) HashMap(java.util.HashMap) List(java.util.List) Test(org.junit.Test)

Example 14 with Partition

use of org.apache.samza.Partition in project samza by apache.

the class TestPartitionDesctiptorUtil method testKeyOverriding.

@Test
public void testKeyOverriding() {
    Map<Partition, List<String>> input = new HashMap<>();
    input.put(new Partition(0), Collections.singletonList("path_0"));
    input.put(new Partition(0), Collections.singletonList("new_path_0"));
    String json = PartitionDescriptorUtil.getJsonFromDescriptorMap(input);
    Map<Partition, List<String>> output = PartitionDescriptorUtil.getDescriptorMapFromJson(json);
    Assert.assertEquals(1, output.entrySet().size());
    Assert.assertTrue(output.containsKey(new Partition(0)));
    Assert.assertEquals("new_path_0", output.get(new Partition(0)).get(0));
}
Also used : Partition(org.apache.samza.Partition) HashMap(java.util.HashMap) List(java.util.List) Test(org.junit.Test)

Example 15 with Partition

use of org.apache.samza.Partition in project samza by apache.

the class TestPartitionDesctiptorUtil method testSingleEntry.

@Test
public void testSingleEntry() {
    Map<Partition, List<String>> input = new HashMap<>();
    input.put(new Partition(1), Collections.singletonList("random_path_1"));
    String json = PartitionDescriptorUtil.getJsonFromDescriptorMap(input);
    Map<Partition, List<String>> output = PartitionDescriptorUtil.getDescriptorMapFromJson(json);
    Assert.assertEquals(1, output.entrySet().size());
    Assert.assertTrue(output.containsKey(new Partition(1)));
    Assert.assertEquals("random_path_1", output.get(new Partition(1)).get(0));
}
Also used : Partition(org.apache.samza.Partition) HashMap(java.util.HashMap) List(java.util.List) Test(org.junit.Test)

Aggregations

Partition (org.apache.samza.Partition)42 Test (org.junit.Test)31 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)30 List (java.util.List)15 HashMap (java.util.HashMap)13 IncomingMessageEnvelope (org.apache.samza.system.IncomingMessageEnvelope)11 ArrayList (java.util.ArrayList)10 SystemStreamPartitionMetadata (org.apache.samza.system.SystemStreamMetadata.SystemStreamPartitionMetadata)8 HashSet (java.util.HashSet)7 FileMetadata (org.apache.samza.system.hdfs.partitioner.FileSystemAdapter.FileMetadata)7 GenericRecord (org.apache.avro.generic.GenericRecord)6 TaskName (org.apache.samza.container.TaskName)6 SamzaException (org.apache.samza.SamzaException)5 Config (org.apache.samza.config.Config)5 SystemStreamMetadata (org.apache.samza.system.SystemStreamMetadata)5 SystemStream (org.apache.samza.system.SystemStream)4 LinkedHashMap (java.util.LinkedHashMap)3 MapConfig (org.apache.samza.config.MapConfig)3 SinglePartitionWithoutOffsetsSystemAdmin (org.apache.samza.util.SinglePartitionWithoutOffsetsSystemAdmin)3 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)2