Search in sources :

Example 26 with ByteArraySegment

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

the class DurableDataLogTestBase method populate.

protected TreeMap<LogAddress, byte[]> populate(DurableDataLog log, int writeCount) {
    TreeMap<LogAddress, byte[]> writtenData = new TreeMap<>(Comparator.comparingLong(LogAddress::getSequence));
    val data = new ArrayList<byte[]>();
    val futures = new ArrayList<CompletableFuture<LogAddress>>();
    for (int i = 0; i < writeCount; i++) {
        byte[] writeData = getWriteData();
        futures.add(log.append(new ByteArraySegment(writeData), TIMEOUT));
        data.add(writeData);
    }
    val addresses = Futures.allOfWithResults(futures).join();
    for (int i = 0; i < data.size(); i++) {
        writtenData.put(addresses.get(i), data.get(i));
    }
    return writtenData;
}
Also used : lombok.val(lombok.val) ByteArraySegment(io.pravega.common.util.ByteArraySegment) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap)

Example 27 with ByteArraySegment

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

the class VersionedSerializerTests method testSingleTypeNonSeekableOutput.

/**
 * Tests Single Type serializer using a Non-Seekable OutputStream.
 */
@Test
public void testSingleTypeNonSeekableOutput() throws IOException {
    testSingleType((tc, s) -> {
        val os = new ByteArrayOutputStream();
        s.serialize(os, tc);
        return new ByteArraySegment(os.toByteArray());
    });
}
Also used : lombok.val(lombok.val) ByteArraySegment(io.pravega.common.util.ByteArraySegment) EnhancedByteArrayOutputStream(io.pravega.common.io.EnhancedByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 28 with ByteArraySegment

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

the class RevisionDataOutputStreamTests method testNonSeekableOutputImpl.

/**
 * Tests the NonSeekableRevisionDataOutput class.
 */
@Test
public void testNonSeekableOutputImpl() throws Exception {
    @Cleanup val s = new ByteArrayOutputStream();
    @Cleanup val impl = RevisionDataOutputStream.wrap(s);
    testImpl(impl, () -> new ByteArraySegment(s.toByteArray()));
}
Also used : lombok.val(lombok.val) ByteArraySegment(io.pravega.common.util.ByteArraySegment) EnhancedByteArrayOutputStream(io.pravega.common.io.EnhancedByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FixedByteArrayOutputStream(io.pravega.common.io.FixedByteArrayOutputStream) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Aggregations

ByteArraySegment (io.pravega.common.util.ByteArraySegment)28 lombok.val (lombok.val)20 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)14 Cleanup (lombok.Cleanup)7 ObjectClosedException (io.pravega.common.ObjectClosedException)6 AssertExtensions (io.pravega.test.common.AssertExtensions)6 Assert (org.junit.Assert)6 IntentionalException (io.pravega.test.common.IntentionalException)5 IOException (java.io.IOException)5 TreeMap (java.util.TreeMap)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 Collectors (java.util.stream.Collectors)5 Rule (org.junit.Rule)5 Timeout (org.junit.rules.Timeout)5 Exceptions (io.pravega.common.Exceptions)4 DurableDataLog (io.pravega.segmentstore.storage.DurableDataLog)4 Duration (java.time.Duration)4 Comparator (java.util.Comparator)4