Search in sources :

Example 6 with Pacemaker

use of org.apache.storm.pacemaker.Pacemaker in project storm by apache.

the class PacemakerTest method testServerExistsTrue.

@Test
public void testServerExistsTrue() {
    String path = "/exists_path";
    String dataString = "pulse data";
    Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
    HBPulse hbPulse = new HBPulse();
    hbPulse.set_id(path);
    hbPulse.set_details(Utils.javaSerialize(dataString));
    messageWithRandId(HBServerMessageType.SEND_PULSE, HBMessageData.pulse(hbPulse));
    handler.handleMessage(hbMessage, true);
    messageWithRandId(HBServerMessageType.EXISTS, HBMessageData.path(path));
    HBMessage badResponse = handler.handleMessage(hbMessage, false);
    HBMessage goodResponse = handler.handleMessage(hbMessage, true);
    Assert.assertEquals(mid, badResponse.get_message_id());
    Assert.assertEquals(HBServerMessageType.NOT_AUTHORIZED, badResponse.get_type());
    Assert.assertEquals(mid, goodResponse.get_message_id());
    Assert.assertEquals(HBServerMessageType.EXISTS_RESPONSE, goodResponse.get_type());
    Assert.assertTrue(goodResponse.get_data().get_boolval());
}
Also used : HBPulse(org.apache.storm.generated.HBPulse) Pacemaker(org.apache.storm.pacemaker.Pacemaker) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HBMessage(org.apache.storm.generated.HBMessage) Test(org.junit.Test)

Example 7 with Pacemaker

use of org.apache.storm.pacemaker.Pacemaker in project storm by apache.

the class PacemakerTest method testServerSendPulseGetPulse.

@Test
public void testServerSendPulseGetPulse() {
    String path = "/pulsepath";
    String dataString = "pulse data";
    Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
    HBPulse hbPulse = new HBPulse();
    hbPulse.set_id(path);
    hbPulse.set_details(Utils.javaSerialize(dataString));
    messageWithRandId(HBServerMessageType.SEND_PULSE, HBMessageData.pulse(hbPulse));
    HBMessage sendResponse = handler.handleMessage(hbMessage, true);
    Assert.assertEquals(mid, sendResponse.get_message_id());
    Assert.assertEquals(HBServerMessageType.SEND_PULSE_RESPONSE, sendResponse.get_type());
    Assert.assertNull(sendResponse.get_data());
    messageWithRandId(HBServerMessageType.GET_PULSE, HBMessageData.path(path));
    HBMessage response = handler.handleMessage(hbMessage, true);
    Assert.assertEquals(mid, response.get_message_id());
    Assert.assertEquals(HBServerMessageType.GET_PULSE_RESPONSE, response.get_type());
    Assert.assertEquals(dataString, Utils.javaDeserialize(response.get_data().get_pulse().get_details(), String.class));
}
Also used : HBPulse(org.apache.storm.generated.HBPulse) Pacemaker(org.apache.storm.pacemaker.Pacemaker) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HBMessage(org.apache.storm.generated.HBMessage) Test(org.junit.Test)

Example 8 with Pacemaker

use of org.apache.storm.pacemaker.Pacemaker in project storm by apache.

the class PacemakerTest method testServerGetAllPulseForPath.

@Test
public void testServerGetAllPulseForPath() {
    Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
    messageWithRandId(HBServerMessageType.GET_ALL_PULSE_FOR_PATH, HBMessageData.path("/testpath"));
    HBMessage badResponse = handler.handleMessage(hbMessage, false);
    HBMessage goodResponse = handler.handleMessage(hbMessage, true);
    Assert.assertEquals(mid, badResponse.get_message_id());
    Assert.assertEquals(HBServerMessageType.NOT_AUTHORIZED, badResponse.get_type());
    Assert.assertEquals(mid, goodResponse.get_message_id());
    Assert.assertEquals(HBServerMessageType.GET_ALL_PULSE_FOR_PATH_RESPONSE, goodResponse.get_type());
    Assert.assertNull(goodResponse.get_data());
}
Also used : Pacemaker(org.apache.storm.pacemaker.Pacemaker) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HBMessage(org.apache.storm.generated.HBMessage) Test(org.junit.Test)

Example 9 with Pacemaker

use of org.apache.storm.pacemaker.Pacemaker in project storm by apache.

the class PacemakerTest method testServerDeletePath.

@Test
public void testServerDeletePath() {
    Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
    makeNode(handler, "/some-root/DELETE_PATH/foo");
    makeNode(handler, "/some-root/DELETE_PATH/bar");
    makeNode(handler, "/some-root/DELETE_PATH/baz");
    makeNode(handler, "/some-root/DELETE_PATH/boo");
    messageWithRandId(HBServerMessageType.DELETE_PATH, HBMessageData.path("/some-root/DELETE_PATH"));
    HBMessage response = handler.handleMessage(hbMessage, true);
    Assert.assertEquals(mid, response.get_message_id());
    Assert.assertEquals(HBServerMessageType.DELETE_PATH_RESPONSE, response.get_type());
    Assert.assertNull(response.get_data());
    messageWithRandId(HBServerMessageType.GET_ALL_NODES_FOR_PATH, HBMessageData.path("/some-root/DELETE_PATH"));
    response = handler.handleMessage(hbMessage, true);
    List<String> pulseIds = response.get_data().get_nodes().get_pulseIds();
    Assert.assertEquals(mid, response.get_message_id());
    Assert.assertEquals(HBServerMessageType.GET_ALL_NODES_FOR_PATH_RESPONSE, response.get_type());
    Assert.assertTrue(pulseIds.isEmpty());
}
Also used : Pacemaker(org.apache.storm.pacemaker.Pacemaker) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HBMessage(org.apache.storm.generated.HBMessage) Test(org.junit.Test)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 HBMessage (org.apache.storm.generated.HBMessage)9 Pacemaker (org.apache.storm.pacemaker.Pacemaker)9 Test (org.junit.Test)9 HBPulse (org.apache.storm.generated.HBPulse)3