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());
}
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);
}
}
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));
}
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));
}
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));
}
Aggregations