Search in sources :

Example 76 with Buffer

use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.

the class BufferTest method testGetSetUnsignedShort.

private void testGetSetUnsignedShort(boolean isLE) throws Exception {
    int numShorts = 100;
    Buffer b = Buffer.buffer(numShorts * 2);
    for (short i = 0; i < numShorts; i++) {
        if (isLE) {
            b.setUnsignedShortLE(i * 2, (short) (Short.MAX_VALUE + (int) i));
        } else {
            b.setUnsignedShort(i * 2, (short) (Short.MAX_VALUE + (int) i));
        }
    }
    for (short i = 0; i < numShorts; i++) {
        if (isLE) {
            assertEquals(Integer.toUnsignedLong(Short.MAX_VALUE + i), b.getUnsignedShortLE(i * 2));
        } else {
            assertEquals(Integer.toUnsignedLong(Short.MAX_VALUE + i), b.getUnsignedShort(i * 2));
        }
    }
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer)

Example 77 with Buffer

use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.

the class BufferTest method testGetBytesWithByteArray.

@Test
public void testGetBytesWithByteArray() throws Exception {
    byte[] bytes = TestUtils.randomByteArray(100);
    Buffer b = Buffer.buffer(bytes);
    byte[] sub = new byte[bytes.length / 2];
    System.arraycopy(bytes, bytes.length / 4, sub, 0, bytes.length / 2);
    byte[] result = new byte[bytes.length / 2];
    b.getBytes(bytes.length / 4, bytes.length / 4 + bytes.length / 2, result);
    assertTrue(TestUtils.byteArraysEqual(sub, result));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 78 with Buffer

use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.

the class BufferTest method testAppendMedium.

@Test
public void testAppendMedium() {
    Buffer b = Buffer.buffer(TestUtils.randomByteArray(100));
    b.appendMedium(MEDIUM_MAX_VALUE);
    assertEquals(103, b.length());
    b.appendMediumLE(MEDIUM_MAX_VALUE);
    assertEquals(106, b.length());
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 79 with Buffer

use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.

the class BufferTest method testGetDouble.

@Test
public void testGetDouble() throws Exception {
    int numDoubles = 100;
    Buffer b = Buffer.buffer(numDoubles * 8);
    for (int i = 0; i < numDoubles; i++) {
        b.setDouble(i * 8, i);
    }
    for (int i = 0; i < numDoubles; i++) {
        assertEquals((double) i, b.getDouble(i * 8), 0);
    }
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 80 with Buffer

use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.

the class BufferTest method testGetBytesWithBadOffset.

@Test(expected = IndexOutOfBoundsException.class)
public void testGetBytesWithBadOffset() throws Exception {
    byte[] bytes = TestUtils.randomByteArray(100);
    Buffer b = Buffer.buffer(bytes);
    byte[] result = new byte[bytes.length / 2];
    b.getBytes(bytes.length / 4, bytes.length / 4 + bytes.length / 2, result, -1);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

Buffer (io.vertx.core.buffer.Buffer)1052 Test (org.junit.Test)604 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)256 Future (io.vertx.core.Future)253 AtomicReference (java.util.concurrent.atomic.AtomicReference)237 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)235 Handler (io.vertx.core.Handler)230 Vertx (io.vertx.core.Vertx)185 TestUtils (io.vertx.test.core.TestUtils)177 JsonObject (io.vertx.core.json.JsonObject)172 TimeUnit (java.util.concurrent.TimeUnit)161 CountDownLatch (java.util.concurrent.CountDownLatch)153 List (java.util.List)152 Consumer (java.util.function.Consumer)149 Function (java.util.function.Function)142 ReadStream (io.vertx.core.streams.ReadStream)139 Context (io.vertx.core.Context)135 ArrayList (java.util.ArrayList)132 MultiMap (io.vertx.core.MultiMap)130 Assume (org.junit.Assume)130