_verifyCounts(1L, store);
// then verify we can see it via iteration
final AtomicInteger count = new AtomicInteger(0);
store.iterateEntriesByModifiedTime(StoreOperationSource.REQUEST, null, 1L,
new StorableLastModIterationCallback() {
@Override
public IterationAction verifyTimestamp(long timestamp) {
if (timestamp != startTime) {
throw new IllegalStateException("Wrong timestamp, "+timestamp+", expected "+startTime);
}
return IterationAction.PROCESS_ENTRY;
}
@Override
public IterationAction verifyKey(StorableKey key) {
if (!key.equals(KEY1)) {
throw new IllegalStateException("Wrong key: "+key);
}
return IterationAction.PROCESS_ENTRY;
}
@Override
public IterationAction processEntry(Storable entry) {
count.addAndGet(1);
return IterationAction.PROCESS_ENTRY;
}
});
assertEquals(1, count.get());
// then add another entry; but in "wrong order"
final long time2 = timeMaster.forceCurrentTimeMillis(startTime - 200L).currentTimeMillis();
final StorableKey KEY2 = storableKey("data/entry/2");
final byte[] SMALL_DATA2 = "Foo".getBytes("UTF-8");
metadata = new StorableCreationMetadata(
/*existing compression*/ null,
calcChecksum32(SMALL_DATA2), HashConstants.NO_CHECKSUM);
resp = store.insert(StoreOperationSource.REQUEST, null,
KEY2, new ByteArrayInputStream(SMALL_DATA2),
metadata, ByteContainer.simple(CUSTOM_METADATA_IN));
assertTrue(resp.succeeded());
assertNull(resp.getPreviousEntry());
_verifyCounts(2L, store);
// and verify order
final ArrayList<Long> timestamps = new ArrayList<Long>();
final ArrayList<StorableKey> keys = new ArrayList<StorableKey>();
store.iterateEntriesByModifiedTime(StoreOperationSource.REQUEST, null,
0L, new StorableLastModIterationCallback() {
long lastTimestamp;
@Override
public IterationAction verifyTimestamp(long timestamp) {
timestamps.add(timestamp);
lastTimestamp = timestamp;
return IterationAction.PROCESS_ENTRY;
}
@Override
public IterationAction verifyKey(StorableKey key) {
keys.add(key);
return IterationAction.PROCESS_ENTRY;
}
@Override
public IterationAction processEntry(Storable entry) {
assertEquals(lastTimestamp, entry.getLastModified());
return IterationAction.PROCESS_ENTRY;
}
});
assertEquals(2, timestamps.size());
assertEquals(2, keys.size());
assertEquals(Long.valueOf(time2), timestamps.get(0));
assertEquals(Long.valueOf(startTime), timestamps.get(1));
assertEquals(KEY2, keys.get(0));
assertEquals(KEY1, keys.get(1));
// finally, traverse partial:
count.set(0);
store.iterateEntriesByModifiedTime(StoreOperationSource.REQUEST, null,
startTime-50L,
new StorableLastModIterationCallback() {
@Override
public IterationAction verifyTimestamp(long timestamp) {
if (timestamp != startTime) {
throw new IllegalStateException("Wrong timestamp, "+timestamp+", expected "+startTime);
}
return IterationAction.PROCESS_ENTRY;
}
@Override
public IterationAction verifyKey(StorableKey key) {
if (!key.equals(KEY1)) {
throw new IllegalStateException("Wrong key: "+key);
}
return IterationAction.PROCESS_ENTRY;
}
@Override
public IterationAction processEntry(Storable entry) {
count.addAndGet(1);
return IterationAction.PROCESS_ENTRY;
}
});
assertEquals(1, count.get());
// and once more, using exact start value
count.set(0);
store.iterateEntriesByModifiedTime(StoreOperationSource.REQUEST, null,
startTime-200L,
new StorableLastModIterationCallback() {
@Override
public IterationAction verifyTimestamp(long timestamp) {
if ((timestamp != (startTime-200L)) && (timestamp != startTime)) {
throw new IllegalStateException("Wrong timestamp: "+timestamp+" (startTime "+startTime+")");
}