Search in sources :

Example 6 with DeferredSerialization

use of org.voltcore.utils.DeferredSerialization in project voltdb by VoltDB.

the class TestRateLimitedClientNotifier method testNode.

/*
     * Check that equality and hash code work as expected
     * where nodes that are heads of identical lists are identical
     * and nodes that have the same supplier and next node are also
     * equal
     */
@Test
public void testNode() throws Exception {
    Supplier<DeferredSerialization> sup = getSupplier(null);
    Node n = new Node(sup, null);
    Node n2 = new Node(sup, null);
    Node diffSup = new Node(getSupplier(null), null);
    assertFalse(n.equals(null));
    assertTrue(n.equals(n2));
    assertEquals(n.hashCode(), n2.hashCode());
    assertTrue(n2.equals(n));
    assertTrue(n.equals(n));
    assertFalse(n.equals(diffSup));
    assertFalse(n.hashCode() == diffSup.hashCode());
    Supplier<DeferredSerialization> sup2 = getSupplier(null);
    Node n3 = new Node(sup2, n);
    assertFalse(n3.equals(n2));
    assertFalse(n3.hashCode() == n2.hashCode());
    Node n3_2 = new Node(sup2, n);
    Supplier<DeferredSerialization> sup3 = getSupplier(null);
    Node n4 = new Node(sup3, n3);
    Node n4_2 = new Node(sup3, n3_2);
    assertTrue(n4.equals(n4_2));
    assertTrue(n4.hashCode() == n4_2.hashCode());
}
Also used : Node(org.voltdb.RateLimitedClientNotifier.Node) DeferredSerialization(org.voltcore.utils.DeferredSerialization) Test(org.junit.Test)

Example 7 with DeferredSerialization

use of org.voltcore.utils.DeferredSerialization in project voltdb by VoltDB.

the class TestRateLimitedClientNotifier method testNodeCaching.

/*
     * Check caching postfixes of nodes works
     */
@Test
public void testNodeCaching() throws Exception {
    Supplier<DeferredSerialization> sup = getSupplier(null);
    Node n = getNode(sup, null);
    Node n2 = getNode(sup, null);
    Node diffSup = getNode(getSupplier(null), null);
    assertFalse(n.equals(null));
    assertTrue(n.equals(n2));
    assertEquals(n.hashCode(), n2.hashCode());
    assertTrue(n2.equals(n));
    assertTrue(n.equals(n));
    assertFalse(n.equals(diffSup));
    assertFalse(n.hashCode() == diffSup.hashCode());
    Supplier<DeferredSerialization> sup2 = getSupplier(null);
    Node n3 = getNode(sup2, n);
    assertFalse(n3.equals(n2));
    assertFalse(n3.hashCode() == n2.hashCode());
    Node n3_2 = getNode(sup2, n);
    Supplier<DeferredSerialization> sup3 = getSupplier(null);
    Node n4 = getNode(sup3, n3);
    Node n4_2 = getNode(sup3, n3_2);
    assertTrue(n4.equals(n4_2));
    assertTrue(n4.hashCode() == n4_2.hashCode());
    assertEquals(cache.size(), 4);
}
Also used : Node(org.voltdb.RateLimitedClientNotifier.Node) DeferredSerialization(org.voltcore.utils.DeferredSerialization) Test(org.junit.Test)

Example 8 with DeferredSerialization

use of org.voltcore.utils.DeferredSerialization in project voltdb by VoltDB.

the class TestRateLimitedClientNotifier method testDedupeMultiple.

/*
     * Test that submitting a dupe of a second notification is skipped
     */
@Test
public void testDedupeMultiple() throws Exception {
    ByteBuffer buf = ByteBuffer.allocate(1);
    Supplier<DeferredSerialization> sup = getSupplier(buf);
    Supplier<DeferredSerialization> sup2 = getSupplier(buf);
    notifier.queueNotification(ImmutableList.of(cihm), sup, Predicates.<ClientInterfaceHandleManager>alwaysTrue());
    notifier.queueNotification(ImmutableList.of(cihm), sup2, Predicates.<ClientInterfaceHandleManager>alwaysTrue());
    notifier.queueNotification(ImmutableList.of(cihm), sup2, Predicates.<ClientInterfaceHandleManager>alwaysTrue());
    notifier.start();
    messages.take();
    messages.take();
    assertNull(mws.m_messages.poll(50, TimeUnit.MILLISECONDS));
}
Also used : DeferredSerialization(org.voltcore.utils.DeferredSerialization) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 9 with DeferredSerialization

use of org.voltcore.utils.DeferredSerialization in project voltdb by VoltDB.

the class TestRateLimitedClientNotifier method testDedupe.

/*
     * Test that submitting a dupe notification is skipped
     * Multiple dedupe tests follow that cover different internal code paths
     * for deduping
     */
@Test
public void testDedupe() throws Exception {
    ByteBuffer buf = ByteBuffer.allocate(1);
    Supplier<DeferredSerialization> sup = getSupplier(buf);
    notifier.queueNotification(ImmutableList.of(cihm), sup, Predicates.<ClientInterfaceHandleManager>alwaysTrue());
    notifier.queueNotification(ImmutableList.of(cihm), sup, Predicates.<ClientInterfaceHandleManager>alwaysTrue());
    notifier.start();
    mws.m_messages.take();
    assertNull(mws.m_messages.poll(50, TimeUnit.MILLISECONDS));
}
Also used : DeferredSerialization(org.voltcore.utils.DeferredSerialization) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 10 with DeferredSerialization

use of org.voltcore.utils.DeferredSerialization in project voltdb by VoltDB.

the class TestClientInterface method testGC.

@Test
public void testGC() throws Exception {
    ByteBuffer msg = createMsg("@GC");
    ClientResponseImpl resp = m_ci.handleRead(msg, m_handler, m_cxn);
    assertNull(resp);
    DeferredSerialization ds = responsesDS.take();
    ByteBuffer b = ByteBuffer.allocate(ds.getSerializedSize());
    ds.serialize(b);
    resp = new ClientResponseImpl();
    b.position(4);
    resp.initFromBuffer(b);
    assertEquals(ClientResponse.SUCCESS, resp.getStatus());
    VoltTable vt = resp.getResults()[0];
    assertTrue(vt.advanceRow());
    //System.gc() should take at least a little time
    assertTrue(resp.getResults()[0].getLong(0) > 10000);
}
Also used : DeferredSerialization(org.voltcore.utils.DeferredSerialization) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

DeferredSerialization (org.voltcore.utils.DeferredSerialization)16 ByteBuffer (java.nio.ByteBuffer)11 Test (org.junit.Test)8 Node (org.voltdb.RateLimitedClientNotifier.Node)2 ByteBuf (io.netty_voltpatches.buffer.ByteBuf)1 CompositeByteBuf (io.netty_voltpatches.buffer.CompositeByteBuf)1 IOException (java.io.IOException)1 Matchers.anyLong (org.mockito.Matchers.anyLong)1 VoltMessage (org.voltcore.messaging.VoltMessage)1 BBContainer (org.voltcore.utils.DBBPool.BBContainer)1 InitiateResponseMessage (org.voltdb.messaging.InitiateResponseMessage)1 Iv2InitiateTaskMessage (org.voltdb.messaging.Iv2InitiateTaskMessage)1