Search in sources :

Example 16 with SystemStreamPartition

use of org.apache.samza.system.SystemStreamPartition 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 17 with SystemStreamPartition

use of org.apache.samza.system.SystemStreamPartition 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 18 with SystemStreamPartition

use of org.apache.samza.system.SystemStreamPartition in project samza by apache.

the class HdfsSystemConsumer method doPoll.

private void doPoll(MultiFileHdfsReader reader) {
    SystemStreamPartition systemStreamPartition = reader.getSystemStreamPartition();
    while (reader.hasNext() && !isShutdown) {
        IncomingMessageEnvelope messageEnvelope = reader.readNext();
        offerMessage(systemStreamPartition, messageEnvelope);
        consumerMetrics.incNumEvents(systemStreamPartition);
        consumerMetrics.incTotalNumEvents();
    }
    offerMessage(systemStreamPartition, IncomingMessageEnvelope.buildEndOfStreamEnvelope(systemStreamPartition));
    reader.close();
}
Also used : IncomingMessageEnvelope(org.apache.samza.system.IncomingMessageEnvelope) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition)

Example 19 with SystemStreamPartition

use of org.apache.samza.system.SystemStreamPartition in project samza by apache.

the class TestMultiFileHdfsReader method testSequentialRead.

@Test
public void testSequentialRead() throws Exception {
    SystemStreamPartition ssp = new SystemStreamPartition("hdfs", "testStream", new Partition(0));
    MultiFileHdfsReader multiReader = new MultiFileHdfsReader(HdfsReaderFactory.ReaderType.AVRO, ssp, Arrays.asList(descriptors), "0:0");
    int index = 0;
    while (multiReader.hasNext()) {
        GenericRecord record = (GenericRecord) multiReader.readNext().getMessage();
        Assert.assertEquals(index % NUM_EVENTS, record.get(FIELD_1));
        Assert.assertEquals("string_" + (index % NUM_EVENTS), record.get(FIELD_2).toString());
        index++;
    }
    Assert.assertEquals(3 * NUM_EVENTS, index);
    multiReader.close();
}
Also used : Partition(org.apache.samza.Partition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) GenericRecord(org.apache.avro.generic.GenericRecord) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Test(org.junit.Test)

Example 20 with SystemStreamPartition

use of org.apache.samza.system.SystemStreamPartition in project samza by apache.

the class TestMultiFileHdfsReader method testOutOfRangeFileIndex.

@Test(expected = SamzaException.class)
public void testOutOfRangeFileIndex() {
    SystemStreamPartition ssp = new SystemStreamPartition("hdfs", "testStream", new Partition(0));
    new MultiFileHdfsReader(HdfsReaderFactory.ReaderType.AVRO, ssp, Arrays.asList(descriptors), "3:0");
    Assert.fail();
}
Also used : Partition(org.apache.samza.Partition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Test(org.junit.Test)

Aggregations

SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)43 Partition (org.apache.samza.Partition)29 Test (org.junit.Test)26 HashMap (java.util.HashMap)17 HashSet (java.util.HashSet)17 TaskName (org.apache.samza.container.TaskName)13 IncomingMessageEnvelope (org.apache.samza.system.IncomingMessageEnvelope)13 Config (org.apache.samza.config.Config)10 Set (java.util.Set)8 MapConfig (org.apache.samza.config.MapConfig)7 GenericRecord (org.apache.avro.generic.GenericRecord)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 SystemStream (org.apache.samza.system.SystemStream)5 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)4 SystemStreamMetadata (org.apache.samza.system.SystemStreamMetadata)4 LinkedHashMap (java.util.LinkedHashMap)3 SamzaException (org.apache.samza.SamzaException)3 TaskInstance (org.apache.samza.container.TaskInstance)3 SystemConsumer (org.apache.samza.system.SystemConsumer)3