Search in sources :

Example 16 with HBMessage

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

the class PacemakerTest method testServerExistsFalse.

@Test
public void testServerExistsFalse() {
    Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
    messageWithRandId(HBServerMessageType.EXISTS, 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.EXISTS_RESPONSE, goodResponse.get_type());
    Assert.assertFalse(goodResponse.get_data().get_boolval());
}
Also used : Pacemaker(org.apache.storm.pacemaker.Pacemaker) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HBMessage(org.apache.storm.generated.HBMessage) Test(org.junit.Test)

Example 17 with HBMessage

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

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

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

use of org.apache.storm.generated.HBMessage 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)22 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 Pacemaker (org.apache.storm.pacemaker.Pacemaker)9 Test (org.junit.Test)9 HBPulse (org.apache.storm.generated.HBPulse)5 HBMessageData (org.apache.storm.generated.HBMessageData)3 ArrayList (java.util.ArrayList)2 ControlMessage (org.apache.storm.messaging.netty.ControlMessage)2 SaslMessageToken (org.apache.storm.messaging.netty.SaslMessageToken)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 HBNodes (org.apache.storm.generated.HBNodes)1 HBServerMessageType (org.apache.storm.generated.HBServerMessageType)1 INettySerializable (org.apache.storm.messaging.netty.INettySerializable)1 Channel (org.jboss.netty.channel.Channel)1