View Javadoc

1   package org.apache.helix.manager.zk;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Date;
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  import org.apache.helix.HelixException;
27  import org.apache.helix.NotificationContext;
28  import org.apache.helix.manager.zk.DefaultControllerMessageHandlerFactory;
29  import org.apache.helix.manager.zk.DefaultControllerMessageHandlerFactory.DefaultControllerMessageHandler;
30  import org.apache.helix.messaging.handling.MessageHandler;
31  import org.apache.helix.model.Message;
32  import org.apache.helix.model.Message.MessageType;
33  import org.testng.AssertJUnit;
34  import org.testng.annotations.Test;
35  
36  
37  public class TestDefaultControllerMsgHandlerFactory
38  {
39    @Test()
40    public void testDefaultControllerMsgHandlerFactory()
41    {
42    	System.out.println("START TestDefaultControllerMsgHandlerFactory at " + new Date(System.currentTimeMillis()));
43  
44      DefaultControllerMessageHandlerFactory facotry = new DefaultControllerMessageHandlerFactory();
45  
46      Message message = new Message(MessageType.NO_OP, "0");
47      NotificationContext context = new NotificationContext(null);
48  
49      boolean exceptionCaught = false;
50      try
51      {
52        MessageHandler handler = facotry.createHandler(message, context);
53      } catch (HelixException e)
54      {
55        exceptionCaught = true;
56      }
57      AssertJUnit.assertTrue(exceptionCaught);
58  
59      message = new Message(MessageType.CONTROLLER_MSG, "1");
60      exceptionCaught = false;
61      try
62      {
63        MessageHandler handler = facotry.createHandler(message, context);
64      } catch (HelixException e)
65      {
66        exceptionCaught = true;
67      }
68      AssertJUnit.assertFalse(exceptionCaught);
69  
70      Map<String, String> resultMap = new HashMap<String, String>();
71      message = new Message(MessageType.NO_OP, "3");
72      DefaultControllerMessageHandler defaultHandler = new DefaultControllerMessageHandler(message, context);
73      try
74      {
75        defaultHandler.handleMessage();
76      } catch (HelixException e)
77      {
78        exceptionCaught = true;
79      }
80      catch (InterruptedException e)
81      {
82        // TODO Auto-generated catch block
83        e.printStackTrace();
84      }
85      AssertJUnit.assertTrue(exceptionCaught);
86  
87      message = new Message(MessageType.CONTROLLER_MSG, "4");
88      defaultHandler = new DefaultControllerMessageHandler(message, context);
89      exceptionCaught = false;
90      try
91      {
92        defaultHandler.handleMessage();
93      } catch (HelixException e)
94      {
95        exceptionCaught = true;
96      }
97      catch (InterruptedException e)
98      {
99        // TODO Auto-generated catch block
100       e.printStackTrace();
101     }
102     AssertJUnit.assertFalse(exceptionCaught);
103     System.out.println("END TestDefaultControllerMsgHandlerFactory at " + new Date(System.currentTimeMillis()));
104   }
105 
106 }