View Javadoc

1   package org.apache.helix.mock.controller;
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.io.IOException;
23  import java.util.ArrayList;
24  
25  import org.codehaus.jackson.JsonGenerationException;
26  import org.codehaus.jackson.map.JsonMappingException;
27  
28  public class MockControllerProcess
29  {
30  
31    /**
32     * @param args
33     * @throws IOException
34     * @throws JsonMappingException
35     * @throws JsonGenerationException
36     * @throws InterruptedException
37     */
38    public static void main(String[] args) throws JsonGenerationException,
39        JsonMappingException, InterruptedException, IOException
40    {
41  
42      MockController storageController = new MockController("cm-instance-0",
43          "localhost:2181", "storage-cluster");
44      MockController relayController = new MockController("cm-instance-0",
45          "localhost:2181", "relay-cluster");
46  
47      ArrayList<String> instanceNames = new ArrayList<String>();
48      instanceNames.add("relay0");
49      instanceNames.add("relay1");
50      instanceNames.add("relay2");
51      instanceNames.add("relay3");
52      instanceNames.add("relay4");
53  
54      relayController.createExternalView(instanceNames, 10, 2, "EspressoDB", 0);
55  
56      // Messages to initiate offline->slave->master->slave transitions
57  
58      storageController.sendMessage("TestMessageId1", "localhost_8900",
59          "Offline", "Slave", "EspressoDB.partition-0", 0);
60      Thread.sleep(10000);
61      storageController.sendMessage("TestMessageId2", "localhost_8900", "Slave",
62          "Master", "EspressoDB.partition-0", 0);
63      Thread.sleep(10000);
64      storageController.sendMessage("TestMessageId3", "localhost_8900", "Master",
65          "Slave", "EspressoDB.partition-0", 0);
66      Thread.sleep(10000);
67  
68      // Change the external view to trigger the consumer to listen from
69      // another relay
70      relayController.createExternalView(instanceNames, 10, 2, "EspressoDB", 10);
71  
72      storageController.sendMessage("TestMessageId4", "localhost_8900", "Slave",
73          "Offline", "EspressoDB.partition-0", 0);
74      Thread.sleep(10000);
75    }
76  
77  }