use of com.github.ambry.clustermap.MockPartitionId in project ambry by linkedin.
the class AmbryServerRequestsTest method ttlUpdateTest.
/**
* Tests for success and failure scenarios for TTL updates
* @throws InterruptedException
* @throws IOException
* @throws MessageFormatException
* @throws StoreException
*/
@Test
public void ttlUpdateTest() throws InterruptedException, IOException, MessageFormatException, StoreException {
MockPartitionId id = (MockPartitionId) clusterMap.getWritablePartitionIds(DEFAULT_PARTITION_CLASS).get(0);
int correlationId = TestUtils.RANDOM.nextInt();
String clientId = TestUtils.getRandomString(10);
BlobId blobId = new BlobId(CommonTestUtils.getCurrentBlobIdVersion(), BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), id, false, BlobId.BlobDataType.DATACHUNK);
long expiresAtMs = Utils.getRandomLong(TestUtils.RANDOM, Long.MAX_VALUE);
long opTimeMs = SystemTime.getInstance().milliseconds();
// storekey not valid for store
doTtlUpdate(correlationId++, clientId, blobId, expiresAtMs, opTimeMs, ServerErrorCode.Blob_Not_Found);
// valid now
validKeysInStore.add(blobId);
doTtlUpdate(correlationId++, clientId, blobId, expiresAtMs, opTimeMs, ServerErrorCode.No_Error);
// after conversion
validKeysInStore.remove(blobId);
BlobId converted = new BlobId(blobId.getVersion(), BlobId.BlobIdType.CRAFTED, blobId.getDatacenterId(), Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), blobId.getPartition(), BlobId.isEncrypted(blobId.getID()), BlobId.BlobDataType.DATACHUNK);
// not in conversion map
doTtlUpdate(correlationId++, clientId, blobId, expiresAtMs, opTimeMs, ServerErrorCode.Blob_Not_Found);
// in conversion map but key not valid
conversionMap.put(blobId, converted);
doTtlUpdate(correlationId++, clientId, blobId, expiresAtMs, opTimeMs, ServerErrorCode.Blob_Not_Found);
// valid now
validKeysInStore.add(converted);
doTtlUpdate(correlationId++, clientId, blobId, expiresAtMs, opTimeMs, ServerErrorCode.No_Error);
// READ_ONLY is fine too
changePartitionState(id, true);
doTtlUpdate(correlationId++, clientId, blobId, expiresAtMs, opTimeMs, ServerErrorCode.No_Error);
changePartitionState(id, false);
miscTtlUpdateFailuresTest();
}
use of com.github.ambry.clustermap.MockPartitionId in project ambry by linkedin.
the class StorageManagerTest method startBlobStoreTest.
/**
* Test start BlobStore with given {@link PartitionId}.
*/
@Test
public void startBlobStoreTest() 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());
// shutdown all the replicas first
for (ReplicaId replica : replicas) {
id = replica.getPartitionId();
assertTrue("Shutdown should succeed on given store", storageManager.shutdownBlobStore(id));
}
ReplicaId replica = replicas.get(0);
id = replica.getPartitionId();
// test start a store successfully
assertTrue("Start should succeed on given store", storageManager.startBlobStore(id));
// test start the store which is already started
assertTrue("Start should succeed on the store which is already started", storageManager.startBlobStore(id));
// test invalid partition
replica = invalidPartitionReplicas.get(0);
id = replica.getPartitionId();
assertFalse("Start should fail on given invalid replica", storageManager.startBlobStore(id));
// test start the store whose DiskManager is not running
replica = replicas.get(replicas.size() - 1);
id = replica.getPartitionId();
storageManager.getDiskManager(id).shutdown();
assertFalse("Start should fail on given store whose DiskManager is not running", storageManager.startBlobStore(id));
shutdownAndAssertStoresInaccessible(storageManager, replicas);
}
use of com.github.ambry.clustermap.MockPartitionId 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.MockPartitionId 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.MockPartitionId 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);
}
Aggregations