Search in sources :

Example 11 with BinaryPayloadMessage

use of org.voltcore.messaging.BinaryPayloadMessage in project voltdb by VoltDB.

the class TestCartographer method testMPIChange.

@Test
public void testMPIChange() throws Exception {
    ZooKeeper zk = getClient(0);
    VoltZK.createPersistentZKNodes(zk);
    LeaderCache mpwriter = new LeaderCache(zk, VoltZK.iv2mpi);
    HostMessenger hm = mock(HostMessenger.class);
    when(hm.getZK()).thenReturn(m_messengers.get(0).getZK());
    Cartographer dut = new Cartographer(hm, 0, false);
    mpwriter.start(true);
    // initial master
    mpwriter.put(MpInitiator.MP_INIT_PID, 0l);
    verify(hm, timeout(10000)).send(anyLong(), any(VoltMessage.class));
    reset(hm);
    // Now change the master
    mpwriter.put(MpInitiator.MP_INIT_PID, 3l);
    ArgumentCaptor<Long> hsIdCaptor = ArgumentCaptor.forClass(Long.class);
    ArgumentCaptor<BinaryPayloadMessage> bpmCaptor = ArgumentCaptor.forClass(BinaryPayloadMessage.class);
    verify(hm, timeout(10000)).send(hsIdCaptor.capture(), bpmCaptor.capture());
    JSONObject jsObj = new JSONObject(new String(bpmCaptor.getValue().m_payload, "UTF-8"));
    final int partitionId = jsObj.getInt(Cartographer.JSON_PARTITION_ID);
    final long initiatorHSId = jsObj.getLong(Cartographer.JSON_INITIATOR_HSID);
    assertEquals(MpInitiator.MP_INIT_PID, partitionId);
    assertEquals(3, initiatorHSId);
    mpwriter.shutdown();
}
Also used : BinaryPayloadMessage(org.voltcore.messaging.BinaryPayloadMessage) VoltMessage(org.voltcore.messaging.VoltMessage) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) JSONObject(org.json_voltpatches.JSONObject) HostMessenger(org.voltcore.messaging.HostMessenger) Matchers.anyLong(org.mockito.Matchers.anyLong) Test(org.junit.Test)

Aggregations

BinaryPayloadMessage (org.voltcore.messaging.BinaryPayloadMessage)11 ByteBuffer (java.nio.ByteBuffer)6 JSONObject (org.json_voltpatches.JSONObject)5 VoltMessage (org.voltcore.messaging.VoltMessage)3 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)2 ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)2 Test (org.junit.Test)2 Matchers.anyLong (org.mockito.Matchers.anyLong)2 HostMessenger (org.voltcore.messaging.HostMessenger)2 LocalObjectMessage (org.voltcore.messaging.LocalObjectMessage)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 CountDownLatch (java.util.concurrent.CountDownLatch)1