Search in sources :

Example 16 with CompositeByteArraySegment

use of io.pravega.common.util.CompositeByteArraySegment in project pravega by pravega.

the class DurableDataLogTestBase method testOpenCloseClient.

/**
 * Tests the ability to reuse the client after closing and reopening it. Verifies the major operations (append,
 * truncate and read), each operation using a different client (each client is used for exactly one operation).
 *
 * @throws Exception If one got thrown.
 */
@Test(timeout = 30000)
public void testOpenCloseClient() throws Exception {
    // This is a very repetitive test; and we only care about "recovery" from no client; all else is already tested.
    final int writeCount = 10;
    TreeMap<LogAddress, byte[]> writtenData = new TreeMap<>(Comparator.comparingLong(LogAddress::getSequence));
    Object context = createSharedContext();
    LogAddress previousAddress = null;
    for (int i = 0; i < writeCount; i++) {
        // Write one entry at each iteration.
        LogAddress currentAddress;
        try (DurableDataLog log = createDurableDataLog(context)) {
            log.initialize(TIMEOUT);
            byte[] writeData = String.format("Write_%s", i).getBytes();
            currentAddress = log.append(new CompositeByteArraySegment(writeData), TIMEOUT).join();
            writtenData.put(currentAddress, writeData);
        }
        // Truncate up to the previous iteration's entry, if any.
        if (previousAddress != null) {
            try (DurableDataLog log = createDurableDataLog(context)) {
                log.initialize(TIMEOUT);
                log.truncate(previousAddress, TIMEOUT).join();
                writtenData.headMap(previousAddress, true).clear();
            }
        }
        // Verify reads.
        try (DurableDataLog log = createDurableDataLog(context)) {
            log.initialize(TIMEOUT);
            verifyReads(log, writtenData);
        }
        previousAddress = currentAddress;
    }
}
Also used : CompositeByteArraySegment(io.pravega.common.util.CompositeByteArraySegment) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 17 with CompositeByteArraySegment

use of io.pravega.common.util.CompositeByteArraySegment in project pravega by pravega.

the class DurableDataLogTestBase method testAppendParallel.

/**
 * Tests the ability to append to a DurableDataLog using parallel writes.
 *
 * @throws Exception If one got thrown.
 */
@Test(timeout = 30000)
public void testAppendParallel() throws Exception {
    try (DurableDataLog log = createDurableDataLog()) {
        log.initialize(TIMEOUT);
        // Only verify sequence number monotonicity. We'll verify reads in its own test.
        List<CompletableFuture<LogAddress>> appendFutures = new ArrayList<>();
        int writeCount = getWriteCount();
        for (int i = 0; i < writeCount; i++) {
            appendFutures.add(log.append(new CompositeByteArraySegment(getWriteData()), TIMEOUT));
        }
        val results = Futures.allOfWithResults(appendFutures).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
        for (int i = 0; i < results.size(); i++) {
            LogAddress address = results.get(i);
            Assert.assertNotNull("No address returned from append() for index " + i, address);
            if (i > 0) {
                AssertExtensions.assertGreaterThan("Sequence Number is not monotonically increasing.", results.get(i - 1).getSequence(), address.getSequence());
            }
        }
    }
}
Also used : CompositeByteArraySegment(io.pravega.common.util.CompositeByteArraySegment) lombok.val(lombok.val) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

CompositeByteArraySegment (io.pravega.common.util.CompositeByteArraySegment)17 Test (org.junit.Test)15 lombok.val (lombok.val)14 ArrayList (java.util.ArrayList)11 DurableDataLog (io.pravega.segmentstore.storage.DurableDataLog)6 ObjectClosedException (io.pravega.common.ObjectClosedException)5 RetriesExhaustedException (io.pravega.common.util.RetriesExhaustedException)4 LogAddress (io.pravega.segmentstore.storage.LogAddress)4 TreeMap (java.util.TreeMap)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Cleanup (lombok.Cleanup)4 DataLogCorruptedException (io.pravega.segmentstore.storage.DataLogCorruptedException)3 DataLogNotAvailableException (io.pravega.segmentstore.storage.DataLogNotAvailableException)3 DurableDataLogException (io.pravega.segmentstore.storage.DurableDataLogException)3 HashMap (java.util.HashMap)3 CancellationException (java.util.concurrent.CancellationException)3 BookKeeper (org.apache.bookkeeper.client.api.BookKeeper)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Lists (com.google.common.collect.Lists)2 Sets (com.google.common.collect.Sets)2