Search in sources :

Example 1 with HBPulse

use of org.apache.storm.generated.HBPulse in project storm by apache.

the class PacemakerTest method testServerGetPulse.

@Test
public void testServerGetPulse() {
    Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
    makeNode(handler, "/some-root/GET_PULSE");
    messageWithRandId(HBServerMessageType.GET_PULSE, HBMessageData.path("/some-root/GET_PULSE"));
    HBMessage badResponse = handler.handleMessage(hbMessage, false);
    HBMessage goodResponse = handler.handleMessage(hbMessage, true);
    HBPulse goodPulse = goodResponse.get_data().get_pulse();
    Assert.assertEquals(mid, badResponse.get_message_id());
    Assert.assertEquals(HBServerMessageType.NOT_AUTHORIZED, badResponse.get_type());
    Assert.assertNull(badResponse.get_data());
    Assert.assertEquals(mid, goodResponse.get_message_id());
    Assert.assertEquals(HBServerMessageType.GET_PULSE_RESPONSE, goodResponse.get_type());
    Assert.assertEquals("/some-root/GET_PULSE", goodPulse.get_id());
    Assert.assertEquals("nothing", Utils.javaDeserialize(goodPulse.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 2 with HBPulse

use of org.apache.storm.generated.HBPulse in project storm by apache.

the class Pacemaker method getPulse.

private HBMessage getPulse(String path, boolean authenticated) {
    if (authenticated) {
        byte[] details = heartbeats.get(path);
        LOG.debug("Getting Pulse for path [ {} ]...data [ {} ].", path, details);
        meterGetPulseCount.mark();
        if (details != null) {
            meterTotalSentSize.mark(details.length);
        }
        HBPulse hbPulse = new HBPulse();
        hbPulse.set_id(path);
        hbPulse.set_details(details);
        return new HBMessage(HBServerMessageType.GET_PULSE_RESPONSE, HBMessageData.pulse(hbPulse));
    } else {
        return notAuthorized();
    }
}
Also used : HBPulse(org.apache.storm.generated.HBPulse) HBMessage(org.apache.storm.generated.HBMessage)

Example 3 with HBPulse

use of org.apache.storm.generated.HBPulse 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 4 with HBPulse

use of org.apache.storm.generated.HBPulse 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 5 with HBPulse

use of org.apache.storm.generated.HBPulse in project storm by apache.

the class PacemakerTest method makeNode.

private HBMessage makeNode(Pacemaker handler, String path) {
    HBPulse hbPulse = new HBPulse();
    hbPulse.set_id(path);
    hbPulse.set_details(Utils.javaSerialize("nothing"));
    HBMessage message = new HBMessage(HBServerMessageType.SEND_PULSE, HBMessageData.pulse(hbPulse));
    return handler.handleMessage(message, true);
}
Also used : HBPulse(org.apache.storm.generated.HBPulse) HBMessage(org.apache.storm.generated.HBMessage)

Aggregations

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