Search in sources :

Example 1 with HBMessage

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

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

the class PacemakerTest method testServerGetAllNodesForPath.

@Test
public void testServerGetAllNodesForPath() {
    Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
    makeNode(handler, "/some-root-path/foo");
    makeNode(handler, "/some-root-path/bar");
    makeNode(handler, "/some-root-path/baz");
    makeNode(handler, "/some-root-path/boo");
    messageWithRandId(HBServerMessageType.GET_ALL_NODES_FOR_PATH, HBMessageData.path("/some-root-path"));
    HBMessage badResponse = handler.handleMessage(hbMessage, false);
    HBMessage goodResponse = handler.handleMessage(hbMessage, true);
    List<String> pulseIds = goodResponse.get_data().get_nodes().get_pulseIds();
    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_NODES_FOR_PATH_RESPONSE, goodResponse.get_type());
    Assert.assertTrue(pulseIds.contains("foo"));
    Assert.assertTrue(pulseIds.contains("bar"));
    Assert.assertTrue(pulseIds.contains("baz"));
    Assert.assertTrue(pulseIds.contains("boo"));
    makeNode(handler, "/some/deeper/path/foo");
    makeNode(handler, "/some/deeper/path/bar");
    makeNode(handler, "/some/deeper/path/baz");
    messageWithRandId(HBServerMessageType.GET_ALL_NODES_FOR_PATH, HBMessageData.path("/some/deeper/path"));
    badResponse = handler.handleMessage(hbMessage, false);
    goodResponse = handler.handleMessage(hbMessage, true);
    pulseIds = goodResponse.get_data().get_nodes().get_pulseIds();
    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_NODES_FOR_PATH_RESPONSE, goodResponse.get_type());
    Assert.assertTrue(pulseIds.contains("foo"));
    Assert.assertTrue(pulseIds.contains("bar"));
    Assert.assertTrue(pulseIds.contains("baz"));
}
Also used : Pacemaker(org.apache.storm.pacemaker.Pacemaker) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HBMessage(org.apache.storm.generated.HBMessage) Test(org.junit.Test)

Example 3 with HBMessage

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

the class PacemakerTest method testServerDeletePulseId.

@Test
public void testServerDeletePulseId() {
    Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
    makeNode(handler, "/some-root/DELETE_PULSE_ID/foo");
    makeNode(handler, "/some-root/DELETE_PULSE_ID/bar");
    makeNode(handler, "/some-root/DELETE_PULSE_ID/baz");
    makeNode(handler, "/some-root/DELETE_PULSE_ID/boo");
    messageWithRandId(HBServerMessageType.DELETE_PULSE_ID, HBMessageData.path("/some-root/DELETE_PULSE_ID/foo"));
    HBMessage response = handler.handleMessage(hbMessage, true);
    Assert.assertEquals(mid, response.get_message_id());
    Assert.assertEquals(HBServerMessageType.DELETE_PULSE_ID_RESPONSE, response.get_type());
    Assert.assertNull(response.get_data());
    messageWithRandId(HBServerMessageType.GET_ALL_NODES_FOR_PATH, HBMessageData.path("/some-root/DELETE_PULSE_ID"));
    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.assertFalse(pulseIds.contains("foo"));
}
Also used : Pacemaker(org.apache.storm.pacemaker.Pacemaker) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HBMessage(org.apache.storm.generated.HBMessage) Test(org.junit.Test)

Example 4 with HBMessage

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

the class PacemakerTest method testServerCreatePath.

@Test
public void testServerCreatePath() {
    Pacemaker handler = new Pacemaker(new ConcurrentHashMap());
    messageWithRandId(HBServerMessageType.CREATE_PATH, HBMessageData.path("/testpath"));
    HBMessage response = handler.handleMessage(hbMessage, true);
    Assert.assertEquals(mid, response.get_message_id());
    Assert.assertEquals(HBServerMessageType.CREATE_PATH_RESPONSE, response.get_type());
    Assert.assertNull(response.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 5 with HBMessage

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

the class PacemakerClientPool method sendAll.

public List<HBMessage> sendAll(HBMessage m) throws PacemakerConnectionException {
    List<HBMessage> responses = new ArrayList<HBMessage>();
    LOG.debug("Using servers: {}", servers);
    for (String s : servers) {
        try {
            HBMessage response = getClientForServer(s).send(m);
            responses.add(response);
        } catch (PacemakerConnectionException e) {
            LOG.error("Failed to send message to Pacemaker " + s + " " + e.getMessage());
        }
    }
    if (responses.size() == 0) {
        throw new PacemakerConnectionException("Failed to connect to any Pacemaker.");
    }
    return responses;
}
Also used : ArrayList(java.util.ArrayList) 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