use of com.github.ambry.store.MessageInfo in project ambry by linkedin.
the class CloudBlobStoreTest method testGetForExistingBlobs.
/**
* Test cloud store get with a list of blobs that are all valid and previously uploaded in the store
* @param blobIds list of blob ids to get
* @param blobIdToUploadedDataMap map of expected blobid to data buffers
* @throws Exception
*/
private void testGetForExistingBlobs(List<BlobId> blobIds, Map<BlobId, ByteBuffer> blobIdToUploadedDataMap) throws Exception {
StoreInfo storeInfo = store.get(blobIds, EnumSet.noneOf(StoreGetOptions.class));
assertEquals("Number of records returned by get should be same as uploaded", storeInfo.getMessageReadSetInfo().size(), blobIds.size());
for (int i = 0; i < storeInfo.getMessageReadSetInfo().size(); i++) {
MessageInfo messageInfo = storeInfo.getMessageReadSetInfo().get(i);
if (blobIdToUploadedDataMap.containsKey(messageInfo.getStoreKey())) {
ByteBuffer uploadedData = blobIdToUploadedDataMap.get(messageInfo.getStoreKey());
ByteBuffer downloadedData = ByteBuffer.allocate((int) messageInfo.getSize());
WritableByteChannel writableByteChannel = Channels.newChannel(new ByteBufferOutputStream(downloadedData));
storeInfo.getMessageReadSet().writeTo(i, writableByteChannel, 0, messageInfo.getSize());
downloadedData.flip();
assertEquals(uploadedData, downloadedData);
break;
}
}
}
use of com.github.ambry.store.MessageInfo in project ambry by linkedin.
the class CloudTestUtil method addBlobToMessageSet.
/**
* Utility method to add a BlobId and generated byte buffer to the specified MessageWriteSet.
* @param messageWriteSet the {@link MockMessageWriteSet} in which to store the data.
* @param blobId the blobId to add.
* @param size the size of the byte buffer.
* @param expiresAtMs the expiration time.
* @param operationTime the operation time.
* @param isVcr is the test running as vcr.
*/
static void addBlobToMessageSet(MockMessageWriteSet messageWriteSet, BlobId blobId, long size, long expiresAtMs, long operationTime, boolean isVcr) {
long crc = new Random().nextLong();
MessageInfo info = new MessageInfo(blobId, size, false, true, false, expiresAtMs, crc, (short) 50, (short) 100, operationTime, initLifeVersion(isVcr));
ByteBuffer buffer = ByteBuffer.wrap(TestUtils.getRandomBytes((int) size));
messageWriteSet.add(info, buffer);
}
use of com.github.ambry.store.MessageInfo in project ambry by linkedin.
the class CloudTestUtil method addBlobToMessageSet.
/**
* Utility method to generate a BlobId and byte buffer for a blob with specified properties and add them to the specified MessageWriteSet.
* @param messageWriteSet the {@link MockMessageWriteSet} in which to store the data.
* @param size the size of the byte buffer.
* @param expiresAtMs the expiration time.
* @param accountId the account Id.
* @param containerId the container Id.
* @param encrypted the encrypted bit.
* @param deleted true if blob is deleted.
* @param partitionId the partition id.
* @param operationTime the operation time.
* @param isVcr flag to indicate if running as vcr.
* @return the generated {@link BlobId}.
*/
static BlobId addBlobToMessageSet(MockMessageWriteSet messageWriteSet, long size, long expiresAtMs, short accountId, short containerId, boolean encrypted, boolean deleted, PartitionId partitionId, long operationTime, boolean isVcr) {
BlobId id = getUniqueId(accountId, containerId, encrypted, partitionId);
long crc = new Random().nextLong();
MessageInfo info = new MessageInfo(id, size, deleted, true, false, expiresAtMs, crc, accountId, containerId, operationTime, initLifeVersion(isVcr));
ByteBuffer buffer = ByteBuffer.wrap(TestUtils.getRandomBytes((int) size));
messageWriteSet.add(info, buffer);
return id;
}
use of com.github.ambry.store.MessageInfo in project ambry by linkedin.
the class CloudBlobStoreIntegrationTest method testDeleteFromFrontend.
/**
* Test {@link CloudBlobStore#delete} method from frontend.
*/
public void testDeleteFromFrontend() throws StoreException {
// First upload a blob with a life version 2
MockMessageWriteSet messageWriteSet = new MockMessageWriteSet();
addBlobToMessageSet(messageWriteSet, Utils.Infinite_Time, accountId, containerId, partitionId, operationTime, (short) -1);
cloudBlobStore.put(messageWriteSet);
// verify that the blob was uploaded with expected metadata.
StoreInfo storeInfo = cloudBlobStore.get(messageWriteSet.getMessageSetInfo().stream().map(MessageInfo::getStoreKey).collect(Collectors.toList()), EnumSet.allOf(StoreGetOptions.class));
assertEquals("Unexpected live version", 0, storeInfo.getMessageReadSetInfo().get(0).getLifeVersion());
assertEquals("Unexpected delete status", messageWriteSet.getMessageSetInfo().get(0).isDeleted(), storeInfo.getMessageReadSetInfo().get(0).isDeleted());
// Deleting again should fail with ID_Deleted exception.
MessageInfo messageInfo = messageWriteSet.getMessageSetInfo().get(0);
MessageInfo deleteMessageInfo = new MessageInfo(messageInfo.getStoreKey(), messageInfo.getSize(), messageInfo.isDeleted(), messageInfo.isTtlUpdated(), messageInfo.isUndeleted(), messageInfo.getExpirationTimeInMs(), messageInfo.getCrc(), messageInfo.getAccountId(), messageInfo.getContainerId(), messageInfo.getOperationTimeMs(), (short) -1);
try {
cloudBlobStore.delete(Collections.singletonList(deleteMessageInfo));
} catch (StoreException ex) {
assertEquals("Unexpected error code", ex.getErrorCode(), StoreErrorCodes.ID_Deleted);
}
storeInfo = cloudBlobStore.get(messageWriteSet.getMessageSetInfo().stream().map(MessageInfo::getStoreKey).collect(Collectors.toList()), EnumSet.allOf(StoreGetOptions.class));
assertEquals("Unexpected live version", 0, storeInfo.getMessageReadSetInfo().get(0).getLifeVersion());
assertTrue("Unexpected delete status", storeInfo.getMessageReadSetInfo().get(0).isDeleted());
// Restart cloud blob store to clear cache. Deleting again should still fail with ID_Deleted Store Exception.
cloudBlobStore.shutdown();
cloudBlobStore.start();
deleteMessageInfo = new MessageInfo(messageInfo.getStoreKey(), messageInfo.getSize(), messageInfo.isDeleted(), messageInfo.isTtlUpdated(), messageInfo.isUndeleted(), messageInfo.getExpirationTimeInMs(), messageInfo.getCrc(), messageInfo.getAccountId(), messageInfo.getContainerId(), messageInfo.getOperationTimeMs(), (short) 3);
try {
cloudBlobStore.delete(Collections.singletonList(deleteMessageInfo));
} catch (StoreException ex) {
assertEquals("Unexpected error code", ex.getErrorCode(), StoreErrorCodes.ID_Deleted);
}
storeInfo = cloudBlobStore.get(messageWriteSet.getMessageSetInfo().stream().map(MessageInfo::getStoreKey).collect(Collectors.toList()), EnumSet.allOf(StoreGetOptions.class));
assertEquals("Unexpected live version", 3, storeInfo.getMessageReadSetInfo().get(0).getLifeVersion());
assertTrue("Unexpected delete status", storeInfo.getMessageReadSetInfo().get(0).isDeleted());
}
use of com.github.ambry.store.MessageInfo in project ambry by linkedin.
the class CloudBlobStoreIntegrationTest method testUndelete.
/**
* Test {@link CloudBlobStore#undelete} method.
*/
@Test
public void testUndelete() throws StoreException {
MockMessageWriteSet messageWriteSet = new MockMessageWriteSet();
addBlobToMessageSet(messageWriteSet, Utils.Infinite_Time, accountId, containerId, partitionId, operationTime, initLifeVersion(isVcr));
cloudBlobStore.put(messageWriteSet);
// Attempt to undelete a blob that is not deleted. Should fail silently for vcr and throw exception for frontend.
MessageInfo messageInfo = messageWriteSet.getMessageSetInfo().get(0);
MessageInfo undeleteMessageInfo = new MessageInfo(messageInfo.getStoreKey(), messageInfo.getSize(), messageInfo.isDeleted(), messageInfo.isTtlUpdated(), messageInfo.isUndeleted(), messageInfo.getExpirationTimeInMs(), messageInfo.getCrc(), messageInfo.getAccountId(), messageInfo.getContainerId(), messageInfo.getOperationTimeMs(), (isVcr ? (short) 1 : -1));
try {
cloudBlobStore.undelete(undeleteMessageInfo);
if (!isVcr) {
fail("Undelete from frontend of a not deleted blob should throw exception.");
}
} catch (StoreException ex) {
if (isVcr) {
fail("Undelete for the vcr should fail silently");
}
assertEquals("Unexpected error message", StoreErrorCodes.ID_Not_Deleted, ex.getErrorCode());
}
// delete the blob.
MessageInfo deleteMessageInfo = new MessageInfo(messageInfo.getStoreKey(), messageInfo.getSize(), messageInfo.isDeleted(), messageInfo.isTtlUpdated(), messageInfo.isUndeleted(), messageInfo.getExpirationTimeInMs(), messageInfo.getCrc(), messageInfo.getAccountId(), messageInfo.getContainerId(), messageInfo.getOperationTimeMs(), (short) (isVcr ? 1 : -1));
cloudBlobStore.delete(Collections.singletonList(deleteMessageInfo));
// Attempt to undelete should pass
short lifeVersion = cloudBlobStore.undelete(undeleteMessageInfo);
assertEquals("Unexpected life version after undelete", lifeVersion, 1);
}
Aggregations