use of org.apache.samza.system.SystemAdmins in project samza by apache.
the class TestTransactionalStateTaskBackupManager method testGetNewestOffsetsThrowsIfNullSSPMetadata.
@Test(expected = SamzaException.class)
public void testGetNewestOffsetsThrowsIfNullSSPMetadata() {
// empty topic == null newest offset
ContainerStorageManager csm = mock(ContainerStorageManager.class);
KafkaTransactionalStateTaskBackupManager tsm = buildTSM(csm, mock(Partition.class), new StorageManagerUtil());
TaskName taskName = mock(TaskName.class);
String changelogSystemName = "systemName";
String storeName = "storeName";
String changelogStreamName = "changelogName";
String newestChangelogSSPOffset = null;
SystemStream changelogSystemStream = new SystemStream(changelogSystemName, changelogStreamName);
Partition changelogPartition = new Partition(0);
SystemStreamPartition changelogSSP = new SystemStreamPartition(changelogSystemStream, changelogPartition);
java.util.Map<String, SystemStream> storeChangelogs = new HashMap<>();
storeChangelogs.put(storeName, changelogSystemStream);
SystemAdmins systemAdmins = mock(SystemAdmins.class);
SystemAdmin systemAdmin = mock(SystemAdmin.class);
SystemStreamPartitionMetadata metadata = mock(SystemStreamPartitionMetadata.class);
when(metadata.getNewestOffset()).thenReturn(newestChangelogSSPOffset);
when(systemAdmins.getSystemAdmin(changelogSystemName)).thenReturn(systemAdmin);
java.util.Map metadataMap = new HashMap() {
{
put(changelogSSP, null);
}
};
when(systemAdmin.getSSPMetadata(eq(ImmutableSet.of(changelogSSP)))).thenReturn(metadataMap);
// invoke the method
java.util.Map<String, String> offsets = tsm.getNewestChangelogSSPOffsets(taskName, storeChangelogs, changelogPartition, systemAdmins);
// verify results
fail("Should have thrown an exception if admin returned null metadata for changelog SSP");
}
use of org.apache.samza.system.SystemAdmins in project samza by apache.
the class TestTransactionalStateTaskBackupManager method testGetNewestOffsetsThrowsIfNullMetadata.
@Test(expected = SamzaException.class)
public void testGetNewestOffsetsThrowsIfNullMetadata() {
// empty topic == null newest offset
ContainerStorageManager csm = mock(ContainerStorageManager.class);
KafkaTransactionalStateTaskBackupManager tsm = buildTSM(csm, mock(Partition.class), new StorageManagerUtil());
TaskName taskName = mock(TaskName.class);
String changelogSystemName = "systemName";
String storeName = "storeName";
String changelogStreamName = "changelogName";
String newestChangelogSSPOffset = null;
SystemStream changelogSystemStream = new SystemStream(changelogSystemName, changelogStreamName);
Partition changelogPartition = new Partition(0);
SystemStreamPartition changelogSSP = new SystemStreamPartition(changelogSystemStream, changelogPartition);
java.util.Map<String, SystemStream> storeChangelogs = new HashMap<>();
storeChangelogs.put(storeName, changelogSystemStream);
SystemAdmins systemAdmins = mock(SystemAdmins.class);
SystemAdmin systemAdmin = mock(SystemAdmin.class);
SystemStreamPartitionMetadata metadata = mock(SystemStreamPartitionMetadata.class);
when(metadata.getNewestOffset()).thenReturn(newestChangelogSSPOffset);
when(systemAdmins.getSystemAdmin(changelogSystemName)).thenReturn(systemAdmin);
when(systemAdmin.getSSPMetadata(eq(ImmutableSet.of(changelogSSP)))).thenReturn(null);
// invoke the method
java.util.Map<String, String> offsets = tsm.getNewestChangelogSSPOffsets(taskName, storeChangelogs, changelogPartition, systemAdmins);
// verify results
fail("Should have thrown an exception if admin didn't return any metadata");
}
use of org.apache.samza.system.SystemAdmins in project samza by apache.
the class TestTransactionalStateTaskBackupManager method buildTSM.
private KafkaTransactionalStateTaskBackupManager buildTSM(ContainerStorageManager csm, Partition changelogPartition, StorageManagerUtil smu) {
TaskName taskName = new TaskName("Partition 0");
java.util.Map<String, SystemStream> changelogSystemStreams = mock(java.util.Map.class);
SystemAdmins systemAdmins = mock(SystemAdmins.class);
return new KafkaTransactionalStateTaskBackupManager(taskName, changelogSystemStreams, systemAdmins, changelogPartition);
}
use of org.apache.samza.system.SystemAdmins in project samza by apache.
the class TestTransactionalStateTaskBackupManager method testGetNewestOffsetsReturnsNoneForEmptyTopic.
@Test
public void testGetNewestOffsetsReturnsNoneForEmptyTopic() {
// empty topic == null newest offset
ContainerStorageManager csm = mock(ContainerStorageManager.class);
KafkaTransactionalStateTaskBackupManager tsm = buildTSM(csm, mock(Partition.class), new StorageManagerUtil());
TaskName taskName = mock(TaskName.class);
String changelogSystemName = "systemName";
String storeName = "storeName";
String changelogStreamName = "changelogName";
String newestChangelogSSPOffset = null;
SystemStream changelogSystemStream = new SystemStream(changelogSystemName, changelogStreamName);
Partition changelogPartition = new Partition(0);
SystemStreamPartition changelogSSP = new SystemStreamPartition(changelogSystemStream, changelogPartition);
java.util.Map<String, SystemStream> storeChangelogs = new HashMap<String, SystemStream>();
storeChangelogs.put(storeName, changelogSystemStream);
SystemAdmins systemAdmins = mock(SystemAdmins.class);
SystemAdmin systemAdmin = mock(SystemAdmin.class);
SystemStreamPartitionMetadata metadata = mock(SystemStreamPartitionMetadata.class);
when(metadata.getNewestOffset()).thenReturn(newestChangelogSSPOffset);
when(systemAdmins.getSystemAdmin(changelogSystemName)).thenReturn(systemAdmin);
when(systemAdmin.getSSPMetadata(eq(ImmutableSet.of(changelogSSP)))).thenReturn(ImmutableMap.of(changelogSSP, metadata));
// invoke the method
java.util.Map<String, String> stateCheckpointMarkerMap = tsm.getNewestChangelogSSPOffsets(taskName, storeChangelogs, changelogPartition, systemAdmins);
// verify results
assertEquals(1, stateCheckpointMarkerMap.size());
KafkaStateCheckpointMarker kscm = KafkaStateCheckpointMarker.deserialize(stateCheckpointMarkerMap.get(storeName));
assertEquals(changelogSSP, kscm.getChangelogSSP());
assertNull(kscm.getChangelogOffset());
}
use of org.apache.samza.system.SystemAdmins in project samza by apache.
the class AzureJobCoordinator method start.
@Override
public void start() {
LOG.info("Starting Azure job coordinator.");
// The systemAdmins should be started before streamMetadataCache can be used. And it should be stopped when this coordinator is stopped.
systemAdmins = new SystemAdmins(config);
systemAdmins.start();
streamMetadataCache = new StreamMetadataCache(systemAdmins, METADATA_CACHE_TTL_MS, SystemClock.instance());
table.addProcessorEntity(INITIAL_STATE, processorId, false);
// Start scheduler for heartbeating
LOG.info("Starting scheduler for heartbeating.");
heartbeat.scheduleTask();
azureLeaderElector.tryBecomeLeader();
// Start scheduler to check for job model version upgrades
LOG.info("Starting scheduler to check for job model version upgrades.");
versionUpgrade.setStateChangeListener(createJMVersionUpgradeListener());
versionUpgrade.scheduleTask();
// Start scheduler to check for leader liveness
LOG.info("Starting scheduler to check for leader liveness.");
leaderAlive.setStateChangeListener(createLeaderLivenessListener());
leaderAlive.scheduleTask();
}
Aggregations