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;
}
}
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());
}
}
}
}
Aggregations