use of com.palantir.atlasdb.schema.stream.generated.KeyValueTable in project atlasdb by palantir.
the class StreamTest method testConcurrentDelete.
@Test(expected = NullPointerException.class)
public void testConcurrentDelete() throws IOException {
Random rand = new Random();
StreamTestTableFactory tableFactory = StreamTestTableFactory.of();
final byte[] reference = PtBytes.toBytes("ref");
final byte[] bytes1 = new byte[2 * StreamTestStreamStore.IN_MEMORY_THRESHOLD];
rand.nextBytes(bytes1);
KeyValueTable.KeyValueRow keyValueRow = KeyValueTable.KeyValueRow.of("ref");
// Store the stream, together with a reference
Long streamId = txManager.runTaskWithRetry(tx -> {
long id = storeStream(defaultStore, bytes1, reference);
KeyValueTable keyValueTable = tableFactory.getKeyValueTable(tx);
keyValueTable.putStreamId(keyValueRow, id);
return id;
});
// Then fetch streamId as an input stream
InputStream stream = txManager.runTaskWithRetry(tx -> defaultStore.loadStream(tx, streamId));
// Delete the streams
txManager.runTaskWithRetry(tx -> {
KeyValueTable keyValueTable = tableFactory.getKeyValueTable(tx);
keyValueTable.delete(keyValueRow);
deleteStream(tableFactory, tx, streamId);
return null;
});
// Gives a null pointer exception.
assertStreamHasBytes(stream, bytes1);
}
use of com.palantir.atlasdb.schema.stream.generated.KeyValueTable in project atlasdb by palantir.
the class StreamTest method testOverwrite.
@Test
public void testOverwrite() throws IOException {
Random rand = new Random();
StreamTestTableFactory tableFactory = StreamTestTableFactory.of();
final byte[] reference = PtBytes.toBytes("ref");
final byte[] bytes1 = new byte[2 * StreamTestStreamStore.BLOCK_SIZE_IN_BYTES];
rand.nextBytes(bytes1);
KeyValueTable.KeyValueRow keyValueRow = KeyValueTable.KeyValueRow.of("ref");
// Store the stream, together with a reference
Long streamId = txManager.runTaskWithRetry(tx -> {
long id = storeStream(defaultStore, bytes1, reference);
KeyValueTable keyValueTable = tableFactory.getKeyValueTable(tx);
keyValueTable.putStreamId(keyValueRow, id);
return id;
});
// Then fetch streamId as an input stream
InputStream firstStream = txManager.runTaskWithRetry(tx -> defaultStore.loadStream(tx, streamId));
// Then store "ref" -> some_other_stream
final byte[] bytes2 = new byte[2 * StreamTestStreamStore.BLOCK_SIZE_IN_BYTES];
rand.nextBytes(bytes2);
storeStreamAndReference(tableFactory, keyValueRow, reference, bytes2);
// Then continue to read - it should be OK
assertStreamHasBytes(firstStream, bytes1);
}
use of com.palantir.atlasdb.schema.stream.generated.KeyValueTable in project atlasdb by palantir.
the class StreamTest method storeStreamAndReference.
private void storeStreamAndReference(StreamTestTableFactory tableFactory, KeyValueTable.KeyValueRow row, byte[] reference, byte[] value) {
txManager.runTaskWithRetry(tx -> {
long id = storeStream(defaultStore, value, reference);
KeyValueTable keyValueTable = tableFactory.getKeyValueTable(tx);
keyValueTable.putStreamId(row, id);
return null;
});
}
Aggregations