use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class StorageManagerTest method shutdownBlobStoreTest.
/**
* Test shutdown blobstore with given {@link PartitionId}.
*/
@Test
public void shutdownBlobStoreTest() throws Exception {
MockDataNodeId dataNode = clusterMap.getDataNodes().get(0);
List<ReplicaId> replicas = clusterMap.getReplicaIds(dataNode);
List<MockDataNodeId> dataNodes = new ArrayList<>();
dataNodes.add(dataNode);
MockPartitionId invalidPartition = new MockPartitionId(Long.MAX_VALUE, MockClusterMap.DEFAULT_PARTITION_CLASS, dataNodes, 0);
List<? extends ReplicaId> invalidPartitionReplicas = invalidPartition.getReplicaIds();
StorageManager storageManager = createStorageManager(dataNode, metricRegistry, null);
storageManager.start();
assertEquals("There should be 1 unexpected partition reported", 1, getNumUnrecognizedPartitionsReported());
for (int i = 1; i < replicas.size() - 1; i++) {
ReplicaId replica = replicas.get(i);
PartitionId id = replica.getPartitionId();
assertTrue("Shutdown should succeed on given store", storageManager.shutdownBlobStore(id));
}
// test shutdown the store which is not started
ReplicaId replica = replicas.get(replicas.size() - 1);
PartitionId id = replica.getPartitionId();
Store store = storageManager.getStore(id, false);
store.shutdown();
assertTrue("Shutdown should succeed on the store which is not started", storageManager.shutdownBlobStore(id));
// test shutdown the store whose DiskManager is not running
replica = replicas.get(0);
id = replica.getPartitionId();
storageManager.getDiskManager(id).shutdown();
assertFalse("Shutdown should fail on given store whose DiskManager is not running", storageManager.shutdownBlobStore(id));
// test invalid partition
replica = invalidPartitionReplicas.get(0);
id = replica.getPartitionId();
assertFalse("Shutdown should fail on given invalid replica", storageManager.shutdownBlobStore(id));
shutdownAndAssertStoresInaccessible(storageManager, replicas);
}
use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class StorageManagerTest method skipStoppedStoresTest.
/**
* Test the stopped stores are correctly skipped and not started during StorageManager's startup.
*/
@Test
public void skipStoppedStoresTest() throws Exception {
MockDataNodeId dataNode = clusterMap.getDataNodes().get(0);
List<ReplicaId> replicas = clusterMap.getReplicaIds(dataNode);
ClusterParticipant mockParticipant = new MockClusterParticipant();
mockParticipant.setReplicaStoppedState(Collections.singletonList(replicas.get(0)), true);
StorageManager storageManager = createStorageManager(dataNode, metricRegistry, Collections.singletonList(mockParticipant));
storageManager.start();
assertEquals("There should be no unexpected partitions reported", 0, getNumUnrecognizedPartitionsReported());
for (int i = 0; i < replicas.size(); ++i) {
PartitionId id = replicas.get(i).getPartitionId();
if (i == 0) {
assertNull("Store should be null because stopped stores will be skipped and will not be started", storageManager.getStore(id, false));
assertFalse("Compaction should not be scheduled", storageManager.scheduleNextForCompaction(id));
} else {
Store store = storageManager.getStore(id, false);
assertTrue("Store should be started", store.isStarted());
assertTrue("Compaction should be scheduled", storageManager.scheduleNextForCompaction(id));
}
}
shutdownAndAssertStoresInaccessible(storageManager, replicas);
}
use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class StorageManagerTest method successfulStartupShutdownTest.
/**
* Test that stores for all partitions on a node have been started and partitions not present on this node are
* inaccessible. Also tests all stores are shutdown on shutting down the storage manager
* @throws Exception
*/
@Test
public void successfulStartupShutdownTest() throws Exception {
MockDataNodeId dataNode = clusterMap.getDataNodes().get(0);
List<ReplicaId> replicas = clusterMap.getReplicaIds(dataNode);
StorageManager storageManager = createStorageManager(dataNode, metricRegistry, null);
storageManager.start();
assertEquals("There should be no unexpected partitions reported", 0, getNumUnrecognizedPartitionsReported());
checkStoreAccessibility(replicas, null, storageManager);
Map<String, Counter> counters = metricRegistry.getCounters();
assertEquals(0, getCounterValue(counters, DiskSpaceAllocator.class.getName(), "DiskSpaceAllocatorInitFailureCount"));
assertEquals(0, getCounterValue(counters, DiskManager.class.getName(), "TotalStoreStartFailures"));
assertEquals(0, getCounterValue(counters, DiskManager.class.getName(), "DiskMountPathFailures"));
MockPartitionId invalidPartition = new MockPartitionId(Long.MAX_VALUE, MockClusterMap.DEFAULT_PARTITION_CLASS, Collections.emptyList(), 0);
assertNull("Should not have found a store for an invalid partition.", storageManager.getStore(invalidPartition, false));
assertEquals("Compaction thread count is incorrect", dataNode.getMountPaths().size(), TestUtils.numThreadsByThisName(CompactionManager.THREAD_NAME_PREFIX));
verifyCompactionThreadCount(storageManager, dataNode.getMountPaths().size());
shutdownAndAssertStoresInaccessible(storageManager, replicas);
assertEquals("Compaction thread count is incorrect", 0, storageManager.getCompactionThreadCount());
assertEquals(0, getCounterValue(counters, DiskManager.class.getName(), "TotalStoreShutdownFailures"));
}
use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class StorageManagerTest method getDiskManagerTest.
/**
* Test get DiskManager with given {@link PartitionId}.
*/
@Test
public void getDiskManagerTest() throws Exception {
MockDataNodeId dataNode = clusterMap.getDataNodes().get(0);
List<ReplicaId> replicas = clusterMap.getReplicaIds(dataNode);
List<MockDataNodeId> dataNodes = new ArrayList<>();
dataNodes.add(dataNode);
MockPartitionId invalidPartition = new MockPartitionId(Long.MAX_VALUE, MockClusterMap.DEFAULT_PARTITION_CLASS, dataNodes, 0);
List<? extends ReplicaId> invalidPartitionReplicas = invalidPartition.getReplicaIds();
StorageManager storageManager = createStorageManager(dataNode, metricRegistry, null);
PartitionId id = null;
storageManager.start();
assertEquals("There should be 1 unexpected partition reported", 1, getNumUnrecognizedPartitionsReported());
for (ReplicaId replica : replicas) {
id = replica.getPartitionId();
assertNotNull("DiskManager should not be null for valid partition", storageManager.getDiskManager(id));
}
// test invalid partition
ReplicaId replica = invalidPartitionReplicas.get(0);
id = replica.getPartitionId();
assertNull("DiskManager should be null for invalid partition", storageManager.getDiskManager(id));
shutdownAndAssertStoresInaccessible(storageManager, replicas);
}
use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class StorageManagerTest method unrecognizedDirsOnDiskTest.
/**
* Tests that unrecognized directories are reported correctly
* @throws Exception
*/
@Test
public void unrecognizedDirsOnDiskTest() throws Exception {
MockDataNodeId dataNode = clusterMap.getDataNodes().get(0);
List<ReplicaId> replicas = clusterMap.getReplicaIds(dataNode);
int extraDirsCount = 0;
Set<String> createdMountPaths = new HashSet<>();
for (ReplicaId replicaId : replicas) {
if (createdMountPaths.add(replicaId.getMountPath())) {
int count = TestUtils.RANDOM.nextInt(6) + 5;
createFilesAndDirsAtPath(new File(replicaId.getDiskId().getMountPath()), count - 1, count);
// the extra files should not get reported
extraDirsCount += count;
}
}
StorageManager storageManager = createStorageManager(dataNode, metricRegistry, null);
storageManager.start();
assertEquals("There should be some unexpected partitions reported", extraDirsCount, getNumUnrecognizedPartitionsReported());
checkStoreAccessibility(replicas, null, storageManager);
shutdownAndAssertStoresInaccessible(storageManager, replicas);
}
Aggregations