use of org.apache.samza.metrics.Timer in project samza by apache.
the class TestTaskStorageCommitManager method testThrowOnWriteCheckpointDirIfUnsuccessful.
@Test(expected = SamzaException.class)
public void testThrowOnWriteCheckpointDirIfUnsuccessful() {
ContainerStorageManager containerStorageManager = mock(ContainerStorageManager.class);
StorageEngine mockLPStore = mock(StorageEngine.class);
StoreProperties lpStoreProps = mock(StoreProperties.class);
when(mockLPStore.getStoreProperties()).thenReturn(lpStoreProps);
when(lpStoreProps.isPersistedToDisk()).thenReturn(true);
when(lpStoreProps.isDurableStore()).thenReturn(true);
Path mockPath = mock(Path.class);
when(mockLPStore.checkpoint(any())).thenReturn(Optional.of(mockPath));
TaskInstanceMetrics metrics = mock(TaskInstanceMetrics.class);
Timer checkpointTimer = mock(Timer.class);
when(metrics.storeCheckpointNs()).thenReturn(checkpointTimer);
java.util.Map<String, StorageEngine> taskStores = ImmutableMap.of("loggedPersistentStore", mockLPStore);
java.util.Map<String, SystemStream> storeChangelogsStreams = ImmutableMap.of("loggedPersistentStore", mock(SystemStream.class));
StorageManagerUtil storageManagerUtil = mock(StorageManagerUtil.class);
File tmpTestPath = new File("store-checkpoint-test");
when(storageManagerUtil.getTaskStoreDir(eq(tmpTestPath), eq("loggedPersistentStore"), any(), any())).thenReturn(tmpTestPath);
TaskName taskName = new TaskName("task");
TaskStorageCommitManager commitManager = spy(new TaskStorageCommitManager(taskName, Collections.emptyMap(), containerStorageManager, storeChangelogsStreams, mock(Partition.class), null, null, ForkJoinPool.commonPool(), storageManagerUtil, tmpTestPath, metrics));
java.util.Map<String, String> storeSCM = ImmutableMap.of("loggedPersistentStore", "system;loggedPersistentStoreStream;1", "persistentStore", "system;persistentStoreStream;1", "loggedInMemStore", "system;loggedInMemStoreStream;1", "inMemStore", "system;inMemStoreStream;1");
when(containerStorageManager.getAllStores(taskName)).thenReturn(taskStores);
CheckpointV2 checkpoint = new CheckpointV2(CheckpointId.create(), Collections.emptyMap(), Collections.singletonMap("factory", storeSCM));
doThrow(IOException.class).when(storageManagerUtil).writeCheckpointV2File(eq(tmpTestPath), eq(checkpoint));
commitManager.init();
// Should throw samza exception since writeCheckpointV2 failed
commitManager.writeCheckpointToStoreDirectories(checkpoint);
}
use of org.apache.samza.metrics.Timer in project samza by apache.
the class TestTaskStorageCommitManager method testRemoveOldCheckpointsWhenBaseDirContainsRegularFiles.
@Test
public void testRemoveOldCheckpointsWhenBaseDirContainsRegularFiles() {
ContainerStorageManager containerStorageManager = mock(ContainerStorageManager.class);
CheckpointManager checkpointManager = mock(CheckpointManager.class);
TaskBackupManager taskBackupManager1 = mock(TaskBackupManager.class);
TaskBackupManager taskBackupManager2 = mock(TaskBackupManager.class);
File durableStoreDir = mock(File.class);
TaskInstanceMetrics metrics = mock(TaskInstanceMetrics.class);
Timer checkpointTimer = mock(Timer.class);
when(metrics.storeCheckpointNs()).thenReturn(checkpointTimer);
StorageManagerUtil storageManagerUtil = mock(StorageManagerUtil.class);
TaskName taskName = new TaskName("task1");
Map<String, TaskBackupManager> backupManagers = ImmutableMap.of("factory1", taskBackupManager1, "factory2", taskBackupManager2);
when(containerStorageManager.getAllStores(taskName)).thenReturn(Collections.emptyMap());
TaskStorageCommitManager cm = new TaskStorageCommitManager(taskName, backupManagers, containerStorageManager, Collections.emptyMap(), new Partition(1), checkpointManager, new MapConfig(), ForkJoinPool.commonPool(), storageManagerUtil, durableStoreDir, metrics);
File mockStoreDir = mock(File.class);
String mockStoreDirName = "notDirectory";
when(durableStoreDir.listFiles()).thenReturn(new File[] { mockStoreDir });
when(mockStoreDir.getName()).thenReturn(mockStoreDirName);
when(storageManagerUtil.getTaskStoreDir(eq(durableStoreDir), eq(mockStoreDirName), eq(taskName), eq(TaskMode.Active))).thenReturn(mockStoreDir);
// null here can happen if listFiles is called on a non-directory
when(mockStoreDir.listFiles(any(FileFilter.class))).thenReturn(null);
cm.cleanUp(CheckpointId.create(), new HashMap<>()).join();
verify(durableStoreDir).listFiles();
verify(mockStoreDir).listFiles(any(FileFilter.class));
verify(storageManagerUtil).getTaskStoreDir(eq(durableStoreDir), eq(mockStoreDirName), eq(taskName), eq(TaskMode.Active));
}
use of org.apache.samza.metrics.Timer in project samza by apache.
the class TestTaskStorageCommitManager method testSnapshotAndCommitAllFactories.
@Test
public void testSnapshotAndCommitAllFactories() {
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);
TaskInstanceMetrics metrics = mock(TaskInstanceMetrics.class);
Timer checkpointTimer = mock(Timer.class);
when(metrics.storeCheckpointNs()).thenReturn(checkpointTimer);
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, metrics);
when(checkpointManager.readLastCheckpoint(taskName)).thenReturn(checkpoint);
cm.init();
verify(taskBackupManager1).init(eq(checkpoint));
verify(taskBackupManager2).init(eq(checkpoint));
CheckpointId newCheckpointId = CheckpointId.create();
Map<String, String> factory1Checkpoints = ImmutableMap.of("store1", "system;stream;1", "store2", "system;stream;2");
Map<String, String> factory2Checkpoints = ImmutableMap.of("store1", "blobId1", "store2", "blobId2");
when(containerStorageManager.getAllStores(taskName)).thenReturn(Collections.emptyMap());
when(taskBackupManager1.snapshot(newCheckpointId)).thenReturn(factory1Checkpoints);
when(taskBackupManager2.snapshot(newCheckpointId)).thenReturn(factory2Checkpoints);
when(taskBackupManager1.upload(newCheckpointId, factory1Checkpoints)).thenReturn(CompletableFuture.completedFuture(factory1Checkpoints));
when(taskBackupManager2.upload(newCheckpointId, factory2Checkpoints)).thenReturn(CompletableFuture.completedFuture(factory2Checkpoints));
Map<String, Map<String, String>> snapshotSCMs = cm.snapshot(newCheckpointId);
cm.upload(newCheckpointId, snapshotSCMs);
// Test flow for snapshot
verify(taskBackupManager1).snapshot(newCheckpointId);
verify(taskBackupManager2).snapshot(newCheckpointId);
// Test flow for upload
verify(taskBackupManager1).upload(newCheckpointId, factory1Checkpoints);
verify(taskBackupManager2).upload(newCheckpointId, factory2Checkpoints);
verify(checkpointTimer).update(anyLong());
}
use of org.apache.samza.metrics.Timer in project samza by apache.
the class TestTaskStorageCommitManager method testCleanupAllBackupManagers.
@Test
public void testCleanupAllBackupManagers() {
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);
File durableStoreDir = mock(File.class);
when(durableStoreDir.listFiles()).thenReturn(new File[0]);
TaskInstanceMetrics metrics = mock(TaskInstanceMetrics.class);
Timer checkpointTimer = mock(Timer.class);
when(metrics.storeCheckpointNs()).thenReturn(checkpointTimer);
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(), durableStoreDir, metrics);
when(checkpointManager.readLastCheckpoint(taskName)).thenReturn(checkpoint);
when(containerStorageManager.getAllStores(taskName)).thenReturn(Collections.emptyMap());
when(taskBackupManager1.cleanUp(any(), any())).thenReturn(CompletableFuture.<Void>completedFuture(null));
when(taskBackupManager2.cleanUp(any(), any())).thenReturn(CompletableFuture.<Void>completedFuture(null));
Map<String, String> factory1Checkpoints = ImmutableMap.of("store1", "system;stream;1", "store2", "system;stream;2");
Map<String, String> factory2Checkpoints = ImmutableMap.of("store1", "blobId1", "store2", "blobId2");
Map<String, Map<String, String>> factoryCheckpointsMap = ImmutableMap.of("factory1", factory1Checkpoints, "factory2", factory2Checkpoints);
when(taskBackupManager1.cleanUp(any(), any())).thenReturn(CompletableFuture.completedFuture(null));
when(taskBackupManager2.cleanUp(any(), any())).thenReturn(CompletableFuture.completedFuture(null));
CheckpointId newCheckpointId = CheckpointId.create();
cm.cleanUp(newCheckpointId, factoryCheckpointsMap).join();
verify(taskBackupManager1).cleanUp(newCheckpointId, factory1Checkpoints);
verify(taskBackupManager2).cleanUp(newCheckpointId, factory2Checkpoints);
}
use of org.apache.samza.metrics.Timer in project samza by apache.
the class TestTaskStorageCommitManager method testCleanupFailsIfBackupManagerNotInitiated.
@Test
public void testCleanupFailsIfBackupManagerNotInitiated() {
CheckpointManager checkpointManager = mock(CheckpointManager.class);
ContainerStorageManager containerStorageManager = mock(ContainerStorageManager.class);
Checkpoint checkpoint = mock(Checkpoint.class);
File durableStoreDir = mock(File.class);
when(durableStoreDir.listFiles()).thenReturn(new File[0]);
TaskInstanceMetrics metrics = mock(TaskInstanceMetrics.class);
Timer checkpointTimer = mock(Timer.class);
when(metrics.storeCheckpointNs()).thenReturn(checkpointTimer);
TaskName taskName = new TaskName("task1");
when(containerStorageManager.getAllStores(taskName)).thenReturn(Collections.emptyMap());
TaskStorageCommitManager cm = new TaskStorageCommitManager(taskName, Collections.emptyMap(), containerStorageManager, Collections.emptyMap(), new Partition(1), checkpointManager, new MapConfig(), ForkJoinPool.commonPool(), new StorageManagerUtil(), durableStoreDir, metrics);
when(checkpointManager.readLastCheckpoint(taskName)).thenReturn(checkpoint);
Map<String, Map<String, String>> factoryCheckpointsMap = ImmutableMap.of(// factory 3 should be ignored
"factory3", // factory 3 should be ignored
Collections.emptyMap());
CheckpointId newCheckpointId = CheckpointId.create();
cm.cleanUp(newCheckpointId, factoryCheckpointsMap);
// should not fail the commit because the job should ignore any factories checkpoints not initialized
// in case the user is in a migration phase from on state backend to another
}
Aggregations