Examples of HelixTaskExecutor


Examples of org.apache.helix.messaging.handling.HelixTaskExecutor

  }

  @Test ()
  public void testTaskCancellation() throws InterruptedException
  {
    HelixTaskExecutor executor = new HelixTaskExecutor();
    HelixManager manager = new MockClusterManager();

    CancellableHandlerFactory factory = new CancellableHandlerFactory();
    executor.registerMessageHandlerFactory(factory.getMessageType(), factory);

    NotificationContext changeContext = new NotificationContext(manager);
    List<Message> msgList = new ArrayList<Message>();

    int nMsgs1 = 0;
    for(int i = 0; i < nMsgs1; i++)
    {
      Message msg = new Message(factory.getMessageType(), UUID.randomUUID().toString());
      msg.setTgtSessionId("*");
      msg.setTgtName("Localhost_1123");
      msg.setSrcName("127.101.1.23_2234");
      msgList.add(msg);
    }

    List<Message> msgListToCancel = new ArrayList<Message>();
    int nMsgs2 = 4;
    for(int i = 0; i < nMsgs2; i++)
    {
      Message msg = new Message(factory.getMessageType(), UUID.randomUUID().toString());
      msg.setTgtSessionId("*");
      msgList.add(msg);
      msg.setTgtName("Localhost_1123");
      msg.setSrcName("127.101.1.23_2234");
      msgListToCancel.add(msg);
    }
    executor.onMessage("someInstance", msgList, changeContext);
    Thread.sleep(500);
    for(int i = 0; i < nMsgs2; i++)
    {
      // executor.cancelTask(msgListToCancel.get(i), changeContext);
      HelixTask task = new HelixTask(msgListToCancel.get(i), changeContext, null, null);
      executor.cancelTask(task);
    }
    Thread.sleep(1500);

    AssertJUnit.assertTrue(factory._processedMsgIds.size() == nMsgs1);
    AssertJUnit.assertTrue(factory._handlersCreated == nMsgs1 + nMsgs2);
View Full Code Here

Examples of org.apache.helix.messaging.handling.HelixTaskExecutor

  @Test ()
  public void testShutdown() throws InterruptedException
  {
     System.out.println("START TestCMTaskExecutor.testShutdown()");
     HelixTaskExecutor executor = new HelixTaskExecutor();
      HelixManager manager = new MockClusterManager();

      TestMessageHandlerFactory factory = new TestMessageHandlerFactory();
      executor.registerMessageHandlerFactory(factory.getMessageType(), factory);

      TestMessageHandlerFactory2 factory2 = new TestMessageHandlerFactory2();
      executor.registerMessageHandlerFactory(factory2.getMessageType(), factory2);

      CancellableHandlerFactory factory3 = new CancellableHandlerFactory();
      executor.registerMessageHandlerFactory(factory3.getMessageType(), factory3);
      int nMsg1 = 10, nMsg2 = 10, nMsg3 = 10;
      List<Message> msgList = new ArrayList<Message>();

      for(int i = 0; i < nMsg1; i++)
      {
        Message msg = new Message(factory.getMessageType(), UUID.randomUUID().toString());
        msg.setTgtSessionId("*");
        msg.setTgtName("Localhost_1123");
        msg.setSrcName("127.101.1.23_2234");
        msgList.add(msg);
      }

      for(int i = 0; i < nMsg2; i++)
      {
        Message msg = new Message(factory2.getMessageType(), UUID.randomUUID().toString());
        msg.setTgtSessionId("*");
        msgList.add(msg);
        msg.setTgtName("Localhost_1123");
        msg.setSrcName("127.101.1.23_2234");
        msgList.add(msg);
      }

      for(int i = 0; i < nMsg3; i++)
      {
        Message msg = new Message(factory3.getMessageType(), UUID.randomUUID().toString());
        msg.setTgtSessionId("*");
        msgList.add(msg);
        msg.setTgtName("Localhost_1123");
        msg.setSrcName("127.101.1.23_2234");
        msgList.add(msg);
      }
      NotificationContext changeContext = new NotificationContext(manager);
      executor.onMessage("some", msgList, changeContext);
      Thread.sleep(500);
      for(ExecutorService svc : executor._executorMap.values())
      {
        Assert.assertFalse(svc.isShutdown());
      }
      Assert.assertTrue(factory._processedMsgIds.size() > 0);
      executor.shutdown();
      for(ExecutorService svc : executor._executorMap.values())
      {
        Assert.assertTrue(svc.isShutdown());
      }
      System.out.println("END TestCMTaskExecutor.testShutdown()");
View Full Code Here

Examples of org.apache.helix.messaging.handling.HelixTaskExecutor

  @Test ()
  public void testNoRetry() throws InterruptedException
  {
//    String p = "test_";
//    System.out.println(p.substring(p.lastIndexOf('_')+1));
    HelixTaskExecutor executor = new HelixTaskExecutor();
    HelixManager manager = new MockClusterManager();

    CancellableHandlerFactory factory = new CancellableHandlerFactory();
    executor.registerMessageHandlerFactory(factory.getMessageType(), factory);

    NotificationContext changeContext = new NotificationContext(manager);

    List<Message> msgList = new ArrayList<Message>();
    int nMsgs2 = 4;
    // Test the case in which retry = 0
    for(int i = 0; i < nMsgs2; i++)
    {
      Message msg = new Message(factory.getMessageType(), UUID.randomUUID().toString());
      msg.setTgtSessionId("*");
      msg.setTgtName("Localhost_1123");
      msg.setSrcName("127.101.1.23_2234");
      msg.setExecutionTimeout((i+1) * 600);
      msgList.add(msg);
    }
    executor.onMessage("someInstance", msgList, changeContext);
   
    Thread.sleep(4000);

    AssertJUnit.assertTrue(factory._handlersCreated ==  nMsgs2);
    AssertJUnit.assertEquals(factory._timedOutMsgIds.size() , 2);
View Full Code Here

Examples of org.apache.helix.messaging.handling.HelixTaskExecutor

  {
//    Logger.getRootLogger().setLevel(Level.INFO);

//    String p = "test_";
//    System.out.println(p.substring(p.lastIndexOf('_')+1));
    HelixTaskExecutor executor = new HelixTaskExecutor();
    HelixManager manager = new MockClusterManager();

    CancellableHandlerFactory factory = new CancellableHandlerFactory();
    executor.registerMessageHandlerFactory(factory.getMessageType(), factory);

    NotificationContext changeContext = new NotificationContext(manager);

    List<Message> msgList = new ArrayList<Message>();

//    factory.reset();
//    msgList.clear();
    // Test the case that the message are executed for the second time
    int nMsgs2 = 4;
    for(int i = 0; i < nMsgs2; i++)
    {
      Message msg = new Message(factory.getMessageType(), UUID.randomUUID().toString());
      msg.setTgtSessionId("*");
      msg.setTgtName("Localhost_1123");
      msg.setSrcName("127.101.1.23_2234");
      msg.setExecutionTimeout((i+1) * 600);
      msg.setRetryCount(1);
      msgList.add(msg);
    }
    executor.onMessage("someInstance", msgList, changeContext);
    Thread.sleep(3500);
    AssertJUnit.assertEquals(factory._processedMsgIds.size(),3);
    AssertJUnit.assertTrue(msgList.get(0).getRecord().getSimpleField("Cancelcount").equals("2"));
    AssertJUnit.assertTrue(msgList.get(1).getRecord().getSimpleField("Cancelcount").equals("1"));
    AssertJUnit.assertEquals(factory._timedOutMsgIds.size(),2);
View Full Code Here

Examples of org.apache.helix.messaging.handling.HelixTaskExecutor

public class TestHelixTaskHandler
{
  @Test()
  public void testInvocation() throws Exception
  {
    HelixTaskExecutor executor = new HelixTaskExecutor();
    System.out.println("START TestCMTaskHandler.testInvocation()");
    Message message = new Message(MessageType.STATE_TRANSITION, "Some unique id");

    message.setSrcName("cm-instance-0");
    message.setTgtSessionId("1234");
View Full Code Here

Examples of org.apache.helix.messaging.handling.HelixTaskExecutor

  @Test()
  public void testInvocationAnnotated() throws Exception
  {
    System.out.println("START TestCMTaskHandler.testInvocationAnnotated() at "
        + new Date(System.currentTimeMillis()));
    HelixTaskExecutor executor = new HelixTaskExecutor();
    Message message = new Message(MessageType.STATE_TRANSITION, "Some unique id");
    message.setSrcName("cm-instance-0");
    message.setTgtSessionId("1234");
    message.setFromState("Offline");
    message.setToState("Slave");
View Full Code Here

Examples of org.apache.helix.messaging.handling.HelixTaskExecutor

 
  public DefaultMessagingService(HelixManager manager)
  {
    _manager = manager;
    _evaluator = new CriteriaEvaluator();
    _taskExecutor = new HelixTaskExecutor();
    _asyncCallbackService = new AsyncCallbackService();
    _taskExecutor.registerMessageHandlerFactory(MessageType.TASK_REPLY.toString(),
                                                _asyncCallbackService);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.