Search in sources :

Example 11 with WriteBuffer

use of org.gridgain.internal.h2.mvstore.WriteBuffer in project 468H2Project by lukeunderwood42.

the class TestDataUtils method testWriteBuffer.

private static void testWriteBuffer() {
    WriteBuffer buff = new WriteBuffer();
    buff.put(new byte[1500000]);
    buff.put(new byte[1900000]);
}
Also used : WriteBuffer(org.h2.mvstore.WriteBuffer)

Example 12 with WriteBuffer

use of org.gridgain.internal.h2.mvstore.WriteBuffer in project jackrabbit-oak by apache.

the class PersistentCache method broadcast.

void broadcast(CacheType type, Function<WriteBuffer, Void> writer) {
    Broadcaster b = broadcaster;
    if (b == null) {
        return;
    }
    WriteBuffer buff = writeBuffer.get();
    if (buff == null) {
        buff = new WriteBuffer();
        writeBuffer.set(buff);
    }
    buff.clear();
    // space for the length
    buff.putInt(0);
    buff.put(broadcastId);
    buff.put((byte) type.ordinal());
    writer.apply(buff);
    ByteBuffer byteBuff = buff.getBuffer();
    int length = byteBuff.position();
    byteBuff.limit(length);
    // write length
    byteBuff.putInt(0, length);
    byteBuff.position(0);
    b.send(byteBuff);
}
Also used : WriteBuffer(org.h2.mvstore.WriteBuffer) Broadcaster(org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.Broadcaster) UDPBroadcaster(org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.UDPBroadcaster) InMemoryBroadcaster(org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.InMemoryBroadcaster) TCPBroadcaster(org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.TCPBroadcaster) ByteBuffer(java.nio.ByteBuffer)

Example 13 with WriteBuffer

use of org.gridgain.internal.h2.mvstore.WriteBuffer in project h2database by h2database.

the class TestDataUtils method testWriteBuffer.

private static void testWriteBuffer() {
    WriteBuffer buff = new WriteBuffer();
    buff.put(new byte[1500000]);
    buff.put(new byte[1900000]);
}
Also used : WriteBuffer(org.h2.mvstore.WriteBuffer)

Example 14 with WriteBuffer

use of org.gridgain.internal.h2.mvstore.WriteBuffer in project SpringStudy by myounghaklee.

the class TestMVStoreConcurrent method testConcurrentDataType.

private void testConcurrentDataType() throws InterruptedException {
    final ObjectDataType type = new ObjectDataType();
    final Object[] data = new Object[] { null, -1, 1, 10, "Hello", new Object[] { new byte[] { (byte) -1, (byte) 1 }, null }, new Object[] { new byte[] { (byte) 1, (byte) -1 }, 10 }, new Object[] { new byte[] { (byte) -1, (byte) 1 }, 20L }, new Object[] { new byte[] { (byte) 1, (byte) -1 }, 5 } };
    Arrays.sort(data, type::compare);
    Task[] tasks = new Task[2];
    for (int i = 0; i < tasks.length; i++) {
        tasks[i] = new Task() {

            @Override
            public void call() {
                Random r = new Random();
                WriteBuffer buff = new WriteBuffer();
                while (!stop) {
                    int a = r.nextInt(data.length);
                    int b = r.nextInt(data.length);
                    int comp;
                    if (r.nextBoolean()) {
                        comp = type.compare(a, b);
                    } else {
                        comp = -type.compare(b, a);
                    }
                    buff.clear();
                    type.write(buff, a);
                    buff.clear();
                    type.write(buff, b);
                    if (a == b) {
                        assertEquals(0, comp);
                    } else {
                        assertEquals(a > b ? 1 : -1, comp);
                    }
                }
            }
        };
        tasks[i].execute();
    }
    try {
        Thread.sleep(100);
    } finally {
        for (Task t : tasks) {
            t.get();
        }
    }
}
Also used : Task(org.h2.util.Task) WriteBuffer(org.h2.mvstore.WriteBuffer) Random(java.util.Random) ObjectDataType(org.h2.mvstore.type.ObjectDataType)

Example 15 with WriteBuffer

use of org.gridgain.internal.h2.mvstore.WriteBuffer in project gridgain by gridgain.

the class TestObjectDataType method test.

private void test(Object last, Object x) {
    ObjectDataType ot = new ObjectDataType();
    // switch to the last type before every operation,
    // to test switching types
    ot.getMemory(last);
    assertTrue(ot.getMemory(x) >= 0);
    ot.getMemory(last);
    assertTrue(ot.getMemory(x) >= 0);
    ot.getMemory(last);
    assertEquals(0, ot.compare(x, x));
    WriteBuffer buff = new WriteBuffer();
    ot.getMemory(last);
    ot.write(buff, x);
    buff.put((byte) 123);
    ByteBuffer bb = buff.getBuffer();
    bb.flip();
    ot.getMemory(last);
    Object y = ot.read(bb);
    assertEquals(123, bb.get());
    assertEquals(0, bb.remaining());
    assertEquals(x.getClass().getName(), y.getClass().getName());
    ot.getMemory(last);
    assertEquals(0, ot.compare(x, y));
    if (x.getClass().isArray()) {
        if (x instanceof byte[]) {
            assertTrue(Arrays.equals((byte[]) x, (byte[]) y));
        } else if (x instanceof boolean[]) {
            assertTrue(Arrays.equals((boolean[]) x, (boolean[]) y));
        } else if (x instanceof short[]) {
            assertTrue(Arrays.equals((short[]) x, (short[]) y));
        } else if (x instanceof float[]) {
            assertTrue(Arrays.equals((float[]) x, (float[]) y));
        } else if (x instanceof double[]) {
            assertTrue(Arrays.equals((double[]) x, (double[]) y));
        } else if (x instanceof char[]) {
            assertTrue(Arrays.equals((char[]) x, (char[]) y));
        } else if (x instanceof int[]) {
            assertTrue(Arrays.equals((int[]) x, (int[]) y));
        } else if (x instanceof long[]) {
            assertTrue(Arrays.equals((long[]) x, (long[]) y));
        } else {
            assertTrue(Arrays.equals((Object[]) x, (Object[]) y));
        }
    } else {
        assertEquals(x.hashCode(), y.hashCode());
        assertTrue(x.equals(y));
    }
}
Also used : WriteBuffer(org.gridgain.internal.h2.mvstore.WriteBuffer) ObjectDataType(org.gridgain.internal.h2.mvstore.type.ObjectDataType) ByteBuffer(java.nio.ByteBuffer)

Aggregations

WriteBuffer (org.h2.mvstore.WriteBuffer)11 ObjectDataType (org.h2.mvstore.type.ObjectDataType)7 ByteBuffer (java.nio.ByteBuffer)5 Random (java.util.Random)5 Task (org.h2.util.Task)4 WriteBuffer (org.gridgain.internal.h2.mvstore.WriteBuffer)3 ObjectDataType (org.gridgain.internal.h2.mvstore.type.ObjectDataType)2 Value (org.gridgain.internal.h2.value.Value)2 VersionedValue (org.gridgain.internal.h2.value.VersionedValue)2 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 Broadcaster (org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.Broadcaster)1 InMemoryBroadcaster (org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.InMemoryBroadcaster)1 TCPBroadcaster (org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.TCPBroadcaster)1 UDPBroadcaster (org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.UDPBroadcaster)1 Compressor (org.gridgain.internal.h2.compress.Compressor)1 SpatialKey (org.gridgain.internal.h2.mvstore.rtree.SpatialKey)1 ResultInterface (org.gridgain.internal.h2.result.ResultInterface)1 Task (org.gridgain.internal.h2.util.Task)1