try {
StorableCreationMetadata metadata = new StorableCreationMetadata(null,
calcChecksum32(DATA_ORIG), HashConstants.NO_CHECKSUM);
metadata.uncompressedSize = -1L;
StorableCreationResult resp = store.insert(StoreOperationSource.REQUEST, null,
KEY1, new ByteArrayInputStream(DATA_ORIG),
metadata, ByteContainer.simple(CUSTOM_METADATA_ORIG));
assertTrue(resp.succeeded());
assertNull(resp.getPreviousEntry());
_verifyCounts(1L, store);
// Then try to overwrite with a newer timestamp
timeMaster.advanceCurrentTimeMillis(1000);
StorableCreationMetadata metadata2 = new StorableCreationMetadata(null,
calcChecksum32(DATA_REPLACE), HashConstants.NO_CHECKSUM);
metadata.uncompressedSize = -1L;
resp = store.upsertConditionally(StoreOperationSource.REQUEST, null,
KEY1, new ByteArrayInputStream(DATA_REPLACE),
metadata2, ByteContainer.simple(CUSTOM_METADATA_REPLACE),
true, checker);
_verifyCounts(1L, store);
final Storable oldEntry = resp.getPreviousEntry();
assertNotNull(oldEntry);
assertTrue(oldEntry.hasExternalData());
if (expSuccess) { // yes, ought to overwrite:
assertTrue("Should succeeed with checker "+checker, resp.succeeded());
} else { // nope, original retained
assertFalse("Should fail with checker "+checker, resp.succeeded());
}
// and then verify
Storable entry = store.findEntry(StoreOperationSource.REQUEST, null, KEY1);
assertNotNull(entry);