use of org.apache.samza.container.TaskName in project samza by apache.
the class TestBlobStoreRestoreManager method testRestoreSkipsStoresWithMissingCheckpointSCM.
@Test
public void testRestoreSkipsStoresWithMissingCheckpointSCM() {
// store renamed from oldStoreName to newStoreName. No SCM for newStoreName in previous checkpoint.
String jobName = "testJobName";
String jobId = "testJobId";
TaskName taskName = mock(TaskName.class);
BlobStoreRestoreManagerMetrics metrics = new BlobStoreRestoreManagerMetrics(new MetricsRegistryMap());
metrics.initStoreMetrics(ImmutableList.of("newStoreName"));
// new store in config
Set<String> storesToRestore = ImmutableSet.of("newStoreName");
SnapshotIndex snapshotIndex = mock(SnapshotIndex.class);
Map<String, Pair<String, SnapshotIndex>> prevStoreSnapshotIndexes = mock(Map.class);
when(prevStoreSnapshotIndexes.containsKey("newStoreName")).thenReturn(false);
DirIndex dirIndex = mock(DirIndex.class);
when(snapshotIndex.getDirIndex()).thenReturn(dirIndex);
CheckpointId checkpointId = CheckpointId.create();
when(snapshotIndex.getSnapshotMetadata()).thenReturn(new SnapshotMetadata(checkpointId, "jobName", "jobId", "taskName", "storeName"));
Path loggedBaseDir = mock(Path.class);
// create store dir to be deleted during restore
StorageConfig storageConfig = mock(StorageConfig.class);
StorageManagerUtil storageManagerUtil = mock(StorageManagerUtil.class);
BlobStoreUtil blobStoreUtil = mock(BlobStoreUtil.class);
DirDiffUtil dirDiffUtil = mock(DirDiffUtil.class);
BlobStoreRestoreManager.restoreStores(jobName, jobId, taskName, storesToRestore, prevStoreSnapshotIndexes, loggedBaseDir.toFile(), storageConfig, metrics, storageManagerUtil, blobStoreUtil, dirDiffUtil, EXECUTOR);
// verify that we checked the previously checkpointed SCMs.
verify(prevStoreSnapshotIndexes, times(1)).containsKey(eq("newStoreName"));
// verify that the store directory restore was never called
verify(blobStoreUtil, times(0)).restoreDir(any(File.class), any(DirIndex.class), any(Metadata.class));
}
use of org.apache.samza.container.TaskName in project samza by apache.
the class TestKafkaChangelogStateBackendFactory method testGetChangelogSSPsForContainerNoChangelogs.
@Test
public void testGetChangelogSSPsForContainerNoChangelogs() {
KafkaChangelogStateBackendFactory factory = new KafkaChangelogStateBackendFactory();
TaskName taskName0 = new TaskName("task0");
TaskName taskName1 = new TaskName("task1");
TaskModel taskModel0 = new TaskModel(taskName0, ImmutableSet.of(new SystemStreamPartition("input", "stream", new Partition(0))), new Partition(10));
TaskModel taskModel1 = new TaskModel(taskName1, ImmutableSet.of(new SystemStreamPartition("input", "stream", new Partition(1))), new Partition(11));
ContainerModel containerModel = new ContainerModel("processorId", ImmutableMap.of(taskName0, taskModel0, taskName1, taskModel1));
Assert.assertEquals(Collections.emptySet(), factory.getChangelogSSPForContainer(Collections.emptyMap(), new ContainerContextImpl(containerModel, null)));
}
use of org.apache.samza.container.TaskName in project samza by apache.
the class TestTaskSideInputHandler method testGetStartingOffsetsWhenStreamMetadataIsNull.
/**
* This test is for cases, when calls to systemAdmin (e.g., KafkaSystemAdmin's) get-stream-metadata method return null.
*/
@Test
public void testGetStartingOffsetsWhenStreamMetadataIsNull() {
final String taskName = "test-get-starting-offset-task";
Set<SystemStreamPartition> ssps = IntStream.range(1, 2).mapToObj(idx -> new SystemStreamPartition(TEST_SYSTEM, TEST_STREAM, new Partition(idx))).collect(Collectors.toSet());
Map<Partition, SystemStreamMetadata.SystemStreamPartitionMetadata> partitionMetadata = ssps.stream().collect(Collectors.toMap(SystemStreamPartition::getPartition, x -> new SystemStreamMetadata.SystemStreamPartitionMetadata(null, "1", "2")));
TaskSideInputHandler handler = new MockTaskSideInputHandlerBuilder(taskName, TaskMode.Active).addStreamMetadata(Collections.singletonMap(new SystemStream(TEST_SYSTEM, TEST_STREAM), new SystemStreamMetadata(TEST_STREAM, partitionMetadata))).addStore(TEST_STORE, ssps).build();
handler.init();
ssps.forEach(ssp -> {
String startingOffset = handler.getStartingOffset(new SystemStreamPartition(TEST_SYSTEM, TEST_STREAM, ssp.getPartition()));
Assert.assertNull("Starting offset should be null", startingOffset);
});
}
use of org.apache.samza.container.TaskName in project samza by apache.
the class TestTaskStorageCommitManager method testCommitManagerStart.
@Test
public void testCommitManagerStart() {
CheckpointManager checkpointManager = mock(CheckpointManager.class);
TaskBackupManager taskBackupManager1 = mock(TaskBackupManager.class);
TaskBackupManager taskBackupManager2 = mock(TaskBackupManager.class);
ContainerStorageManager containerStorageManager = mock(ContainerStorageManager.class);
Checkpoint checkpoint = mock(Checkpoint.class);
TaskName taskName = new TaskName("task1");
Map<String, TaskBackupManager> backupManagers = ImmutableMap.of("factory1", taskBackupManager1, "factory2", taskBackupManager2);
TaskStorageCommitManager cm = new TaskStorageCommitManager(taskName, backupManagers, containerStorageManager, Collections.emptyMap(), new Partition(1), checkpointManager, new MapConfig(), ForkJoinPool.commonPool(), new StorageManagerUtil(), null, null);
when(checkpointManager.readLastCheckpoint(taskName)).thenReturn(checkpoint);
cm.init();
verify(taskBackupManager1).init(eq(checkpoint));
verify(taskBackupManager2).init(eq(checkpoint));
}
use of org.apache.samza.container.TaskName in project samza by apache.
the class TestTaskStorageCommitManager method testCommitManagerStartNullCheckpointManager.
@Test
public void testCommitManagerStartNullCheckpointManager() {
TaskBackupManager taskBackupManager1 = mock(TaskBackupManager.class);
TaskBackupManager taskBackupManager2 = mock(TaskBackupManager.class);
ContainerStorageManager containerStorageManager = mock(ContainerStorageManager.class);
TaskName task = new TaskName("task1");
Map<String, TaskBackupManager> backupManagers = ImmutableMap.of("factory1", taskBackupManager1, "factory2", taskBackupManager2);
TaskStorageCommitManager cm = new TaskStorageCommitManager(task, backupManagers, containerStorageManager, Collections.emptyMap(), new Partition(1), null, new MapConfig(), ForkJoinPool.commonPool(), new StorageManagerUtil(), null, null);
cm.init();
verify(taskBackupManager1).init(eq(null));
verify(taskBackupManager2).init(eq(null));
}
Aggregations