Search in sources :

Example 1 with KeyValueTable

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);
}
Also used : Random(java.util.Random) KeyValueTable(com.palantir.atlasdb.schema.stream.generated.KeyValueTable) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StreamTestTableFactory(com.palantir.atlasdb.schema.stream.generated.StreamTestTableFactory) Test(org.junit.Test)

Example 2 with KeyValueTable

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);
}
Also used : Random(java.util.Random) KeyValueTable(com.palantir.atlasdb.schema.stream.generated.KeyValueTable) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StreamTestTableFactory(com.palantir.atlasdb.schema.stream.generated.StreamTestTableFactory) Test(org.junit.Test)

Example 3 with KeyValueTable

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;
    });
}
Also used : KeyValueTable(com.palantir.atlasdb.schema.stream.generated.KeyValueTable)

Aggregations

KeyValueTable (com.palantir.atlasdb.schema.stream.generated.KeyValueTable)3 StreamTestTableFactory (com.palantir.atlasdb.schema.stream.generated.StreamTestTableFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Random (java.util.Random)2 Test (org.junit.Test)2