Search in sources :

Example 36 with StreamSpec

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

the class TestKafkaSystemAdminJava method testValidateStreamWrongName.

@Test(expected = StreamValidationException.class)
public void testValidateStreamWrongName() {
    SystemAdmin admin = this.basicSystemAdmin;
    StreamSpec spec1 = new StreamSpec("testId", "testStreamName1", "testSystem", 8);
    StreamSpec spec2 = new StreamSpec("testId", "testStreamName2", "testSystem", 8);
    assertTrue("createStream should return true if the stream does not exist and then is created.", admin.createStream(spec1));
    admin.validateStream(spec2);
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) SystemAdmin(org.apache.samza.system.SystemAdmin) Test(org.junit.Test)

Example 37 with StreamSpec

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

the class TestKafkaSystemAdminJava method testValidateStreamWrongPartitionCount.

@Test(expected = StreamValidationException.class)
public void testValidateStreamWrongPartitionCount() {
    SystemAdmin admin = this.basicSystemAdmin;
    StreamSpec spec1 = new StreamSpec("testId", "testStreamPartition", "testSystem", 8);
    StreamSpec spec2 = new StreamSpec("testId", "testStreamPartition", "testSystem", 4);
    assertTrue("createStream should return true if the stream does not exist and then is created.", admin.createStream(spec1));
    admin.validateStream(spec2);
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) SystemAdmin(org.apache.samza.system.SystemAdmin) Test(org.junit.Test)

Example 38 with StreamSpec

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

the class TestKafkaSystemAdminJava method testValidateChangelogStreamDelegatesToValidateStream.

@Test
public void testValidateChangelogStreamDelegatesToValidateStream() {
    final String STREAM = "testChangeLogValidate";
    Properties coordProps = new Properties();
    Map<String, ChangelogInfo> changeLogMap = new HashMap<>();
    changeLogMap.put(STREAM, new ChangelogInfo(3, new Properties()));
    KafkaSystemAdmin systemAdmin = createSystemAdmin(coordProps, 3, Util.javaMapAsScalaMap(changeLogMap));
    SystemAdmin admin = Mockito.spy(systemAdmin);
    StreamSpec spec = new StreamSpec("testId", STREAM, "testSystem", 12);
    admin.createChangelogStream(spec.getPhysicalName(), spec.getPartitionCount());
    admin.validateStream(spec);
    admin.validateChangelogStream(spec.getPhysicalName(), spec.getPartitionCount());
    Mockito.verify(admin).createStream(Mockito.any());
    Mockito.verify(admin, Mockito.times(3)).validateStream(Mockito.any());
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) HashMap(java.util.HashMap) SystemAdmin(org.apache.samza.system.SystemAdmin) Properties(java.util.Properties) Test(org.junit.Test)

Example 39 with StreamSpec

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

the class TestKafkaSystemAdminJava method testCreateCoordinatorStreamDelegatesToCreateStream.

@Test
public void testCreateCoordinatorStreamDelegatesToCreateStream() {
    //coordProps, 3, new scala.collection.immutable.HashMap<>(), 1000);
    KafkaSystemAdmin systemAdmin = createSystemAdmin();
    SystemAdmin admin = Mockito.spy(systemAdmin);
    StreamSpec spec = new StreamSpec("testId", "testCoordinatorStream", "testSystem");
    admin.createCoordinatorStream(spec.getPhysicalName());
    admin.validateStream(spec);
    Mockito.verify(admin).createStream(Mockito.any());
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) SystemAdmin(org.apache.samza.system.SystemAdmin) Test(org.junit.Test)

Example 40 with StreamSpec

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

the class StreamManager method createStreams.

public void createStreams(List<StreamSpec> streams) {
    Multimap<String, StreamSpec> streamsGroupedBySystem = HashMultimap.create();
    streams.forEach(streamSpec -> streamsGroupedBySystem.put(streamSpec.getSystemName(), streamSpec));
    for (Map.Entry<String, Collection<StreamSpec>> entry : streamsGroupedBySystem.asMap().entrySet()) {
        String systemName = entry.getKey();
        SystemAdmin systemAdmin = sysAdmins.get(systemName);
        for (StreamSpec stream : entry.getValue()) {
            LOGGER.info("Creating stream {} with partitions {} on system {}", new Object[] { stream.getPhysicalName(), stream.getPartitionCount(), systemName });
            systemAdmin.createStream(stream);
        }
    }
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) Collection(java.util.Collection) SystemAdmin(org.apache.samza.system.SystemAdmin) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

StreamSpec (org.apache.samza.system.StreamSpec)40 Test (org.junit.Test)35 JobConfig (org.apache.samza.config.JobConfig)24 Config (org.apache.samza.config.Config)22 MapConfig (org.apache.samza.config.MapConfig)20 StreamConfig (org.apache.samza.config.StreamConfig)14 HashMap (java.util.HashMap)12 SystemAdmin (org.apache.samza.system.SystemAdmin)12 ApplicationRunner (org.apache.samza.runtime.ApplicationRunner)9 BiFunction (java.util.function.BiFunction)6 Function (java.util.function.Function)6 Properties (java.util.Properties)5 InputStreamInternalImpl (org.apache.samza.operators.stream.InputStreamInternalImpl)5 IntermediateStreamInternalImpl (org.apache.samza.operators.stream.IntermediateStreamInternalImpl)5 OutputStreamInternalImpl (org.apache.samza.operators.stream.OutputStreamInternalImpl)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Mockito.mock (org.mockito.Mockito.mock)5 Mockito.when (org.mockito.Mockito.when)5 Field (java.lang.reflect.Field)4 StreamApplication (org.apache.samza.application.StreamApplication)4