use of com.github.ambry.clustermap.WriteStatusDelegate in project ambry by linkedin.
the class BlobStoreTest method testClusterManagerWriteStatusDelegateUse.
/**
* Tests blob store use of {@link WriteStatusDelegate}
* @throws StoreException
*/
@Test
public void testClusterManagerWriteStatusDelegateUse() throws StoreException, IOException, InterruptedException {
// Setup threshold test properties, replicaId, mock write status delegate
StoreConfig defaultConfig = changeThreshold(65, 5, true);
StoreTestUtils.MockReplicaId replicaId = getMockReplicaId(tempDirStr);
WriteStatusDelegate writeStatusDelegate = mock(WriteStatusDelegate.class);
when(writeStatusDelegate.unseal(any())).thenReturn(true);
when(writeStatusDelegate.seal(any())).thenReturn(true);
// Restart store
restartStore(defaultConfig, replicaId, writeStatusDelegate);
// Check that after start, because ReplicaId defaults to non-sealed, delegate is not called
verifyZeroInteractions(writeStatusDelegate);
// Verify that putting in data that doesn't go over the threshold doesn't trigger the delegate
put(1, 50, Utils.Infinite_Time);
verifyNoMoreInteractions(writeStatusDelegate);
// Verify that after putting in enough data, the store goes to read only
List<MockId> addedIds = put(4, 900, Utils.Infinite_Time);
verify(writeStatusDelegate, times(1)).seal(replicaId);
// Assumes ClusterParticipant sets replicaId status to true
replicaId.setSealedState(true);
// Change config threshold but with delegate disabled, verify that nothing happens
restartStore(changeThreshold(99, 1, false), replicaId, writeStatusDelegate);
verifyNoMoreInteractions(writeStatusDelegate);
// Change config threshold to higher, see that it gets changed to unsealed on reset
restartStore(changeThreshold(99, 1, true), replicaId, writeStatusDelegate);
verify(writeStatusDelegate, times(1)).unseal(replicaId);
replicaId.setSealedState(false);
// Reset thresholds, verify that it changed back
restartStore(defaultConfig, replicaId, writeStatusDelegate);
verify(writeStatusDelegate, times(2)).seal(replicaId);
replicaId.setSealedState(true);
// Remaining tests only relevant for segmented logs
if (isLogSegmented) {
// Delete added data
for (MockId addedId : addedIds) {
delete(addedId);
}
// Need to restart blob otherwise compaction will ignore segments in journal (which are all segments right now).
// By restarting, only last segment will be in journal
restartStore(defaultConfig, replicaId, writeStatusDelegate);
verifyNoMoreInteractions(writeStatusDelegate);
// Advance time by 8 days, call compaction to compact segments with deleted data, then verify
// that the store is now read-write
time.sleep(TimeUnit.DAYS.toMillis(8));
store.compact(store.getCompactionDetails(new CompactAllPolicy(defaultConfig, time)));
verify(writeStatusDelegate, times(2)).unseal(replicaId);
// Test if replicaId is erroneously true that it updates the status upon startup
replicaId.setSealedState(true);
restartStore(defaultConfig, replicaId, writeStatusDelegate);
verify(writeStatusDelegate, times(3)).unseal(replicaId);
}
store.shutdown();
}
Aggregations