You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ki...@apache.org on 2012/10/25 00:26:41 UTC
[44/47] Refactoring from com.linkedin.helix to org.apache.helix
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/mock/storage/MockTransition.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/mock/storage/MockTransition.java b/helix-core/src/test/java/com/linkedin/helix/mock/storage/MockTransition.java
deleted file mode 100644
index 6edf51e..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/mock/storage/MockTransition.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.mock.storage;
-
-import org.apache.log4j.Logger;
-
-import com.linkedin.helix.NotificationContext;
-import com.linkedin.helix.model.Message;
-
-public class MockTransition
-{
- private static Logger LOG = Logger.getLogger(MockTransition.class);
-
- // called by state model transition functions
- public void doTransition(Message message, NotificationContext context) throws InterruptedException
- {
- LOG.info("default doTransition() invoked");
- }
-
- // called by state model reset function
- public void doReset()
- {
- LOG.info("default doReset() invoked");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/mock/storage/StorageAdapter.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/mock/storage/StorageAdapter.java b/helix-core/src/test/java/com/linkedin/helix/mock/storage/StorageAdapter.java
deleted file mode 100644
index 7e8d90f..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/mock/storage/StorageAdapter.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.mock.storage;
-
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.log4j.Logger;
-
-import com.linkedin.helix.HelixDataAccessor;
-import com.linkedin.helix.HelixManager;
-import com.linkedin.helix.HelixManagerFactory;
-import com.linkedin.helix.ExternalViewChangeListener;
-import com.linkedin.helix.InstanceType;
-import com.linkedin.helix.MessageListener;
-import com.linkedin.helix.mock.consumer.ConsumerAdapter;
-import com.linkedin.helix.mock.consumer.RelayConfig;
-import com.linkedin.helix.mock.consumer.RelayConsumer;
-import com.linkedin.helix.model.Message.MessageType;
-import com.linkedin.helix.participant.StateMachineEngine;
-
-class StorageAdapter
-{
- HelixManager relayHelixManager;
- HelixManager storageHelixManager;
-
- HelixDataAccessor relayClusterClient;
- HelixDataAccessor storageClusterClient;
-
- private ExternalViewChangeListener relayViewHolder;
- private MessageListener messageListener;
-
- // Map<Object, RelayConsumer> relayConsumersMap;
- private final ConsumerAdapter consumerAdapter;
- private final StorageStateModelFactory stateModelFactory;
-
- class partitionData
- {
- long initTime;
- String permissions;
- int generationId;
- long hwm;
- }
-
- Map<String, partitionData> hostedPartitions;
- private final String instanceName;
-
- private static Logger logger = Logger.getLogger(StorageAdapter.class);
-
- public StorageAdapter(String instanceName, String zkConnectString,
- String clusterName, String relayClusterName) throws Exception
- {
-
- this.instanceName = instanceName;
-
- hostedPartitions = new ConcurrentHashMap<String, partitionData>();
-
- storageHelixManager = HelixManagerFactory
- .getZKHelixManager(clusterName, instanceName, InstanceType.PARTICIPANT,
- zkConnectString);
- stateModelFactory = new StorageStateModelFactory(this);
-// StateMachineEngine genericStateMachineHandler = new StateMachineEngine();
- StateMachineEngine stateMach = storageHelixManager.getStateMachineEngine();
- stateMach.registerStateModelFactory("MasterSlave", stateModelFactory);
-
- storageHelixManager.getMessagingService()
- .registerMessageHandlerFactory(MessageType.STATE_TRANSITION.toString(), stateMach);
- storageHelixManager.connect();
- storageClusterClient = storageHelixManager.getHelixDataAccessor();
-
- consumerAdapter = new ConsumerAdapter(instanceName, zkConnectString,
- relayClusterName);
- }
-
- // for every write call
- public boolean isMasterForPartition(Integer partitionId)
- {
- StorageStateModel stateModelForParition = stateModelFactory
- .getStateModelForPartition(partitionId);
- return "MASTER".equals(stateModelForParition.getCurrentState());
- }
-
- // for every read call depending on read scale config
- public boolean isReplicaForPartition(Integer partitionId)
- {
- StorageStateModel stateModelForParition = stateModelFactory
- .getStateModelForPartition(partitionId);
- return "REPLICA".equals(stateModelForParition.getCurrentState());
- }
-
- /**
- * During replication set up which will happen when there is state transition
- * //TODO may not be nee
- */
- void getMasteredPartitions()
- {
-
- }
-
- /*
- * During replication set up which will happen when there is state transition
- *
- * @return
- */
- Map<Integer, RelayConfig> getReplicatedPartitions()
- {
- return null;
- }
-
- /**
- * Will be used in relay consumers, return can be one RelayConfig or List
- * depending on implementation
- */
- List<RelayConfig> getRelaysForPartition(Integer partitionId)
- {
- return null;
- }
-
- void updateHighWaterMarkForPartition(String waterMark, Integer partitionId)
- {
-
- }
-
- public void endProcess()
- {
-
- }
-
- public void start()
- {
- logger.info("Started storage node " + instanceName);
- }
-
- public void setGeneration(String partition, Integer generationId)
- {
- partitionData pdata = hostedPartitions.get(partition);
- pdata.generationId = generationId;
- hostedPartitions.put(partition, pdata);
- }
-
- public void setHwm(String partition, long hwm)
- {
- partitionData pdata = hostedPartitions.get(partition);
- pdata.hwm = hwm;
- hostedPartitions.put(partition, pdata);
- }
-
- // TODO: make sure multiple invocations are possible
- public void init(String partition)
- {
- logger.info("Storage initializing partition " + partition);
- if (hostedPartitions.containsKey(partition))
- {
- logger.info("Partition exists, not reinitializing.");
- } else
- {
- partitionData pdata = new partitionData();
- pdata.initTime = System.currentTimeMillis();
- pdata.permissions = "OFFLINE";
- hostedPartitions.put(partition, pdata);
- }
- logger.info("Storage initialized for partition " + partition);
- }
-
- public void setPermissions(String partition, String permissions)
- {
- partitionData pdata = hostedPartitions.get(partition);
- pdata.permissions = permissions;
- hostedPartitions.put(partition, pdata);
- }
-
- public void waitForWrites(String partition)
- {
- // TODO Auto-generated method stub
-
- }
-
- public RelayConsumer getNewRelayConsumer(String dbName, String partition)
- throws Exception
- {
- logger.info("Got new relayconsumer for " + partition);
- return consumerAdapter.getNewRelayConsumer(dbName, partition);
- }
-
- public void removeConsumer(String partition) throws Exception
- {
- logger.info("Removing consumer for partition " + partition);
- consumerAdapter.removeConsumer(partition);
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/mock/storage/StorageStateModel.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/mock/storage/StorageStateModel.java b/helix-core/src/test/java/com/linkedin/helix/mock/storage/StorageStateModel.java
deleted file mode 100644
index 2cdf13e..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/mock/storage/StorageStateModel.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.mock.storage;
-
-import org.apache.log4j.Logger;
-
-import com.linkedin.helix.NotificationContext;
-import com.linkedin.helix.mock.consumer.RelayConfig;
-import com.linkedin.helix.mock.consumer.RelayConsumer;
-import com.linkedin.helix.model.Message;
-import com.linkedin.helix.participant.statemachine.StateModel;
-
-public class StorageStateModel extends StateModel
-{
-
- // private Map<Integer, RelayConsumer> relayConsumersMap;
- private RelayConsumer consumer = null;
- private RelayConfig relayConfig;
- private final StorageAdapter storage;
-
- private static Logger logger = Logger.getLogger(StorageStateModel.class);
-
- public StorageStateModel(String stateUnitKey, StorageAdapter storageAdapter)
- {
- // relayConsumersMap = new HashMap<Integer,RelayConsumer>();
- storage = storageAdapter;
- // this.consumerAdapter = consumerAdapter;
- }
-
- public RelayConfig getRelayConfig()
- {
- return relayConfig;
- }
-
- public void setRelayConfig(RelayConfig relayConfig)
- {
- this.relayConfig = relayConfig;
- }
-
- void checkDebug(Message task) throws Exception
- {
- // For debugging purposes
- if (task.getDebug() == true)
- {
- throw new Exception("Exception for debug");
- }
- }
-
- // @transition(to='to',from='from',blah blah..)
- public void onBecomeSlaveFromOffline(Message task, NotificationContext context)
- throws Exception
- {
-
- logger.info("Becoming slave from offline");
-
- checkDebug(task);
-
- String partition = task.getPartitionName();
- String[] pdata = partition.split("\\.");
- String dbName = pdata[0];
-
- // Initializations for the storage node to create right tables, indexes
- // etc.
- storage.init(partition);
- storage.setPermissions(partition, "READONLY");
-
- // start consuming from the relay
- consumer = storage.getNewRelayConsumer(dbName, partition);
- consumer.start();
- // TODO: how do we know we are caught up?
-
- logger.info("Became slave for partition " + partition);
- }
-
- // @transition(to='to',from='from',blah blah..)
- public void onBecomeSlaveFromMaster(Message task, NotificationContext context)
- throws Exception
- {
-
- logger.info("Becoming slave from master");
-
- checkDebug(task);
-
- String partition = task.getPartitionName();
- String[] pdata = partition.split("\\.");
- String dbName = pdata[0];
- storage.setPermissions(partition, "READONLY");
- storage.waitForWrites(partition);
-
- // start consuming from the relay
- consumer = storage.getNewRelayConsumer(dbName, partition);
- consumer.start();
-
- logger.info("Becamse slave for partition " + partition);
- }
-
- // @transition(to='to',from='from',blah blah..)
- public void onBecomeMasterFromSlave(Message task, NotificationContext context)
- throws Exception
- {
- logger.info("Becoming master from slave");
-
- checkDebug(task);
-
- String partition = task.getPartitionName();
-
- // stop consumer and refetch from all so all changes are drained
- consumer.flush(); // blocking call
-
- // TODO: publish the hwm somewhere
- long hwm = consumer.getHwm();
- storage.setHwm(partition, hwm);
- storage.removeConsumer(partition);
- consumer = null;
-
- // set generation in storage
- Integer generationId = task.getGeneration();
- storage.setGeneration(partition, generationId);
-
- storage.setPermissions(partition, "READWRITE");
-
- logger.info("Became master for partition " + partition);
- }
-
- // @transition(to='to',from='from',blah blah..)
- public void onBecomeOfflineFromSlave(Message task, NotificationContext context)
- throws Exception
- {
-
- logger.info("Becoming offline from slave");
-
- checkDebug(task);
-
- String partition = task.getPartitionName();
-
- consumer.stop();
- storage.removeConsumer(partition);
- consumer = null;
-
- storage.setPermissions(partition, "OFFLINE");
-
- logger.info("Became offline for partition " + partition);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/mock/storage/StorageStateModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/mock/storage/StorageStateModelFactory.java b/helix-core/src/test/java/com/linkedin/helix/mock/storage/StorageStateModelFactory.java
deleted file mode 100644
index d5dedd3..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/mock/storage/StorageStateModelFactory.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.mock.storage;
-
-import org.apache.log4j.Logger;
-
-import com.linkedin.helix.participant.statemachine.StateModel;
-import com.linkedin.helix.participant.statemachine.StateModelFactory;
-
-public class StorageStateModelFactory extends StateModelFactory
-{
- private static Logger logger = Logger
- .getLogger(StorageStateModelFactory.class);
-
- private StorageAdapter storageAdapter;
-
- // private ConsumerAdapter consumerAdapter;
-
- public StorageStateModelFactory(StorageAdapter storage)
- {
- storageAdapter = storage;
- }
-
- StorageStateModel getStateModelForPartition(Integer partition)
- {
- return null;
- }
-
- @Override
- public StateModel createNewStateModel(String stateUnitKey)
- {
- logger.info("StorageStateModelFactory.getStateModel()");
- return new StorageStateModel(stateUnitKey, storageAdapter);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/model/TestConstraint.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/model/TestConstraint.java b/helix-core/src/test/java/com/linkedin/helix/model/TestConstraint.java
deleted file mode 100644
index 09c67dc..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/model/TestConstraint.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.model;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
-import org.apache.log4j.Logger;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import com.linkedin.helix.PropertyKey.Builder;
-import com.linkedin.helix.TestHelper;
-import com.linkedin.helix.ZNRecord;
-import com.linkedin.helix.ZkUnitTestBase;
-import com.linkedin.helix.manager.zk.ZKHelixDataAccessor;
-import com.linkedin.helix.manager.zk.ZkBaseDataAccessor;
-import com.linkedin.helix.model.ClusterConstraints.ConstraintAttribute;
-import com.linkedin.helix.model.ClusterConstraints.ConstraintItem;
-import com.linkedin.helix.model.ClusterConstraints.ConstraintType;
-import com.linkedin.helix.model.Message.MessageType;
-
-public class TestConstraint extends ZkUnitTestBase
-{
- private static Logger LOG = Logger.getLogger(TestConstraint.class);
-
- @Test
- public void testMsgConstraint()
- {
- String className = getShortClassName();
- System.out.println("START testMsgConstraint() at "
- + new Date(System.currentTimeMillis()));
-
- String clusterName = "CLUSTER_" + className + "_msg";
- TestHelper.setupEmptyCluster(_gZkClient, clusterName);
- ZNRecord record = new ZNRecord("testMsgConstraint");
-
- // constraint0:
- // "MESSAGE_TYPE=STATE_TRANSITION,CONSTRAINT_VALUE=ANY"
- record.setMapField("constraint0", new TreeMap<String, String>());
- record.getMapField("constraint0").put("MESSAGE_TYPE", "STATE_TRANSITION");
- record.getMapField("constraint0").put("CONSTRAINT_VALUE", "ANY");
- ConstraintItem constraint0 = new ConstraintItem(record.getMapField("constraint0"));
-
- // constraint1:
- // "MESSAGE_TYPE=STATE_TRANSITION,TRANSITION=OFFLINE-SLAVE,CONSTRAINT_VALUE=ANY"
- record.setMapField("constraint1", new TreeMap<String, String>());
- record.getMapField("constraint1").put("MESSAGE_TYPE", "STATE_TRANSITION");
- record.getMapField("constraint1").put("TRANSITION", "OFFLINE-SLAVE");
- record.getMapField("constraint1").put("CONSTRAINT_VALUE", "50");
- ConstraintItem constraint1 = new ConstraintItem(record.getMapField("constraint1"));
-
- // constraint2:
- // "MESSAGE_TYPE=STATE_TRANSITION,TRANSITION=OFFLINE-SLAVE,INSTANCE=.*,RESOURCE=TestDB,CONSTRAINT_VALUE=2";
- record.setMapField("constraint2", new TreeMap<String, String>());
- record.getMapField("constraint2").put("MESSAGE_TYPE", "STATE_TRANSITION");
- record.getMapField("constraint2").put("TRANSITION", "OFFLINE-SLAVE");
- record.getMapField("constraint2").put("INSTANCE", ".*");
- record.getMapField("constraint2").put("RESOURCE", "TestDB");
- record.getMapField("constraint2").put("CONSTRAINT_VALUE", "2");
- ConstraintItem constraint2 = new ConstraintItem(record.getMapField("constraint2"));
-
- // constraint3:
- // "MESSAGE_TYPE=STATE_TRANSITION,TRANSITION=OFFLINE-SLAVE,INSTANCE=localhost_12918,RESOURCE=.*,CONSTRAINT_VALUE=1";
- record.setMapField("constraint3", new TreeMap<String, String>());
- record.getMapField("constraint3").put("MESSAGE_TYPE", "STATE_TRANSITION");
- record.getMapField("constraint3").put("TRANSITION", "OFFLINE-SLAVE");
- record.getMapField("constraint3").put("INSTANCE", "localhost_12919");
- record.getMapField("constraint3").put("RESOURCE", ".*");
- record.getMapField("constraint3").put("CONSTRAINT_VALUE", "1");
- ConstraintItem constraint3 = new ConstraintItem(record.getMapField("constraint3"));
-
- // constraint4:
- // "MESSAGE_TYPE=STATE_TRANSITION,TRANSITION=OFFLINE-SLAVE,INSTANCE=.*,RESOURCE=.*,CONSTRAINT_VALUE=10"
- record.setMapField("constraint4", new TreeMap<String, String>());
- record.getMapField("constraint4").put("MESSAGE_TYPE", "STATE_TRANSITION");
- record.getMapField("constraint4").put("TRANSITION", "OFFLINE-SLAVE");
- record.getMapField("constraint4").put("INSTANCE", ".*");
- record.getMapField("constraint4").put("RESOURCE", ".*");
- record.getMapField("constraint4").put("CONSTRAINT_VALUE", "10");
- ConstraintItem constraint4 = new ConstraintItem(record.getMapField("constraint4"));
-
- // constraint5:
- // "MESSAGE_TYPE=STATE_TRANSITION,TRANSITION=OFFLINE-SLAVE,INSTANCE=localhost_12918,RESOURCE=TestDB,CONSTRAINT_VALUE=5"
- record.setMapField("constraint5", new TreeMap<String, String>());
- record.getMapField("constraint5").put("MESSAGE_TYPE", "STATE_TRANSITION");
- record.getMapField("constraint5").put("TRANSITION", "OFFLINE-SLAVE");
- record.getMapField("constraint5").put("INSTANCE", "localhost_12918");
- record.getMapField("constraint5").put("RESOURCE", "TestDB");
- record.getMapField("constraint5").put("CONSTRAINT_VALUE", "5");
- ConstraintItem constraint5 = new ConstraintItem(record.getMapField("constraint5"));
-
- ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
- Builder keyBuilder = accessor.keyBuilder();
-
- accessor.setProperty(keyBuilder.constraint(ConstraintType.MESSAGE_CONSTRAINT.toString()),
- new ClusterConstraints(record));
-
- record =
- accessor.getProperty(keyBuilder.constraint(ConstraintType.MESSAGE_CONSTRAINT.toString()))
- .getRecord();
- ClusterConstraints constraint = new ClusterConstraints(record);
- // System.out.println("constraint: " + constraint);
-
- // message1
- Message msg1 =
- createMessage(MessageType.STATE_TRANSITION,
- "msgId-001",
- "OFFLINE",
- "SLAVE",
- "TestDB",
- "localhost_12918");
-
- Map<ConstraintAttribute, String> msgAttr =
- ClusterConstraints.toConstraintAttributes(msg1);
- Set<ConstraintItem> matches = constraint.match(msgAttr);
- System.out.println(msg1 + " matches(" + matches.size() + "): " + matches);
- Assert.assertEquals(matches.size(), 5);
- Assert.assertTrue(contains(matches, constraint0));
- Assert.assertTrue(contains(matches, constraint1));
- Assert.assertTrue(contains(matches, constraint2));
- Assert.assertTrue(contains(matches, constraint4));
- Assert.assertTrue(contains(matches, constraint5));
-
- // message2
- Message msg2 =
- createMessage(MessageType.STATE_TRANSITION,
- "msgId-002",
- "OFFLINE",
- "SLAVE",
- "TestDB",
- "localhost_12919");
-
- msgAttr = ClusterConstraints.toConstraintAttributes(msg2);
- matches = constraint.match(msgAttr);
- System.out.println(msg2 + " matches(" + matches.size() + "): " + matches);
- Assert.assertEquals(matches.size(), 5);
- Assert.assertTrue(contains(matches, constraint0));
- Assert.assertTrue(contains(matches, constraint1));
- Assert.assertTrue(contains(matches, constraint2));
- Assert.assertTrue(contains(matches, constraint3));
- Assert.assertTrue(contains(matches, constraint4));
-
- System.out.println("END testMsgConstraint() at "
- + new Date(System.currentTimeMillis()));
- }
-
- @Test
- public void testStateConstraint()
- {
- String className = getShortClassName();
- System.out.println("START testStateConstraint() at "
- + new Date(System.currentTimeMillis()));
-
- String clusterName = "CLUSTER_" + className + "_state";
- TestHelper.setupEmptyCluster(_gZkClient, clusterName);
- ZNRecord record = new ZNRecord("testStateConstraint");
-
- // constraint0:
- // "STATE=MASTER,CONSTRAINT_VALUE=1"
- record.setMapField("constraint0", new TreeMap<String, String>());
- record.getMapField("constraint0").put("STATE", "MASTER");
- record.getMapField("constraint0").put("CONSTRAINT_VALUE", "1");
- ConstraintItem constraint0 = new ConstraintItem(record.getMapField("constraint0"));
-
- // constraint1:
- // "STATE=MASTER,RESOURCE=TestDB,CONSTRAINT_VALUE=5"
- record.setMapField("constraint1", new TreeMap<String, String>());
- record.getMapField("constraint1").put("STATE", "MASTER");
- record.getMapField("constraint1").put("RESOURCE", "TestDB");
- record.getMapField("constraint1").put("CONSTRAINT_VALUE", "1");
- ConstraintItem constraint1 = new ConstraintItem(record.getMapField("constraint1"));
-
- // constraint2:
- // "STATE=MASTER,RESOURCE=.*,CONSTRAINT_VALUE=2"
- record.setMapField("constraint2", new TreeMap<String, String>());
- record.getMapField("constraint2").put("STATE", "MASTER");
- record.getMapField("constraint2").put("RESOURCE", ".*");
- record.getMapField("constraint2").put("CONSTRAINT_VALUE", "2");
- ConstraintItem constraint2 = new ConstraintItem(record.getMapField("constraint2"));
-
- ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
- Builder keyBuilder = accessor.keyBuilder();
-
- accessor.setProperty(keyBuilder.constraint(ConstraintType.STATE_CONSTRAINT.toString()),
- new ClusterConstraints(record));
-
- record =
- accessor.getProperty(keyBuilder.constraint(ConstraintType.STATE_CONSTRAINT.toString()))
- .getRecord();
- ClusterConstraints constraint = new ClusterConstraints(record);
- // System.out.println("constraint: " + constraint);
-
- // state1: hit rule2
- Map<ConstraintAttribute, String> stateAttr1 =
- new HashMap<ConstraintAttribute, String>();
- stateAttr1.put(ConstraintAttribute.STATE, "MASTER");
- stateAttr1.put(ConstraintAttribute.RESOURCE, "TestDB");
-
- Set<ConstraintItem> matches = constraint.match(stateAttr1);
- System.out.println(stateAttr1 + " matches(" + matches.size() + "): " + matches);
- Assert.assertEquals(matches.size(), 3);
- Assert.assertTrue(contains(matches, constraint0));
- Assert.assertTrue(contains(matches, constraint1));
- Assert.assertTrue(contains(matches, constraint2));
-
- // matches = selectConstraints(matches, stateAttr1);
- // System.out.println(stateAttr1 + " matches(" + matches.size() + "): " + matches);
- // Assert.assertEquals(matches.size(), 2);
- // Assert.assertTrue(contains(matches, constraint0));
- // Assert.assertTrue(contains(matches, constraint1));
-
- // state2: not hit any rules
- Map<ConstraintAttribute, String> stateAttr2 =
- new HashMap<ConstraintAttribute, String>();
- stateAttr2.put(ConstraintAttribute.STATE, "MASTER");
- stateAttr2.put(ConstraintAttribute.RESOURCE, "MyDB");
-
- matches = constraint.match(stateAttr2);
- System.out.println(stateAttr2 + " matches(" + matches.size() + "): " + matches);
- Assert.assertEquals(matches.size(), 2);
- Assert.assertTrue(contains(matches, constraint0));
- Assert.assertTrue(contains(matches, constraint2));
-
- // matches = selectConstraints(matches, stateAttr2);
- // System.out.println(stateAttr2 + " matches(" + matches.size() + "): " + matches);
- // Assert.assertEquals(matches.size(), 2);
- // Assert.assertTrue(contains(matches, constraint0));
- // Assert.assertTrue(contains(matches, constraint2));
-
- System.out.println("END testStateConstraint() at "
- + new Date(System.currentTimeMillis()));
- }
-
- private boolean contains(Set<ConstraintItem> constraints, ConstraintItem constraint)
- {
- for (ConstraintItem item : constraints)
- {
- if (item.toString().equals(constraint.toString()))
- {
- return true;
- }
- }
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/model/TestIdealState.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/model/TestIdealState.java b/helix-core/src/test/java/com/linkedin/helix/model/TestIdealState.java
deleted file mode 100644
index 5c3de72..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/model/TestIdealState.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.linkedin.helix.model;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import com.linkedin.helix.TestHelper;
-import com.linkedin.helix.model.IdealState.IdealStateModeProperty;
-
-public class TestIdealState
-{
- @Test
- public void testGetInstanceSet()
- {
- String className = TestHelper.getTestClassName();
- String methodName = TestHelper.getTestMethodName();
- String testName = className + "_" + methodName;
- System.out.println("START " + testName + " at "
- + new Date(System.currentTimeMillis()));
-
-
- IdealState idealState = new IdealState("idealState");
- idealState.getRecord().setListField("TestDB_0", Arrays.asList("node_1", "node_2"));
- Map<String, String> instanceState = new HashMap<String, String>();
- instanceState.put("node_3", "MASTER");
- instanceState.put("node_4", "SLAVE");
- idealState.getRecord().setMapField("TestDB_1", instanceState);
-
- // test AUTO mode
- idealState.setIdealStateMode(IdealStateModeProperty.AUTO.toString());
- Set<String> instances = idealState.getInstanceSet("TestDB_0");
-// System.out.println("instances: " + instances);
- Assert.assertEquals(instances.size(), 2, "Should contain node_1 and node_2");
- Assert.assertTrue(instances.contains("node_1"), "Should contain node_1 and node_2");
- Assert.assertTrue(instances.contains("node_2"), "Should contain node_1 and node_2");
-
- instances = idealState.getInstanceSet("TestDB_nonExist_auto");
- Assert.assertEquals(instances, Collections.emptySet(), "Should get empty set");
-
- // test CUSTOMIZED mode
- idealState.setIdealStateMode(IdealStateModeProperty.CUSTOMIZED.toString());
- instances = idealState.getInstanceSet("TestDB_1");
-// System.out.println("instances: " + instances);
- Assert.assertEquals(instances.size(), 2, "Should contain node_3 and node_4");
- Assert.assertTrue(instances.contains("node_3"), "Should contain node_3 and node_4");
- Assert.assertTrue(instances.contains("node_4"), "Should contain node_3 and node_4");
-
- instances = idealState.getInstanceSet("TestDB_nonExist_custom");
- Assert.assertEquals(instances, Collections.emptySet(), "Should get empty set");
-
- System.out.println("END " + testName + " at "
- + new Date(System.currentTimeMillis()));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/monitoring/TestParticipantMonitor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/monitoring/TestParticipantMonitor.java b/helix-core/src/test/java/com/linkedin/helix/monitoring/TestParticipantMonitor.java
deleted file mode 100644
index e29d1b9..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/monitoring/TestParticipantMonitor.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package com.linkedin.helix.monitoring;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanInfo;
-import javax.management.MBeanServerConnection;
-import javax.management.MBeanServerNotification;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectInstance;
-import javax.management.ObjectName;
-
-import org.apache.log4j.Logger;
-import org.testng.AssertJUnit;
-import org.testng.annotations.Test;
-
-import com.linkedin.helix.monitoring.mbeans.ClusterMBeanObserver;
-
-public class TestParticipantMonitor
-{
- static Logger _logger = Logger.getLogger(TestParticipantMonitor.class);
-
- class ParticipantMonitorListener extends ClusterMBeanObserver
- {
- Map<String, Map<String, Object>> _beanValueMap = new HashMap<String, Map<String, Object>>();
-
- public ParticipantMonitorListener(String domain)
- throws InstanceNotFoundException, IOException,
- MalformedObjectNameException, NullPointerException
- {
- super(domain);
- init();
- }
-
- void init()
- {
- try
- {
- Set<ObjectInstance> existingInstances = _server.queryMBeans(new ObjectName(_domain+":Cluster=cluster,*"), null);
- for(ObjectInstance instance : existingInstances)
- {
- String mbeanName = instance.getObjectName().toString();
- // System.out.println("mbeanName: " + mbeanName);
- addMBean(instance.getObjectName());
- }
- }
- catch (Exception e)
- {
- _logger.warn("fail to get all existing mbeans in " + _domain, e);
- }
- }
-
- @Override
- public void onMBeanRegistered(MBeanServerConnection server,
- MBeanServerNotification mbsNotification)
- {
- addMBean(mbsNotification.getMBeanName());
- }
-
- void addMBean(ObjectName beanName)
- {
- try
- {
- MBeanInfo info = _server.getMBeanInfo(beanName);
- MBeanAttributeInfo[] infos = info.getAttributes();
- _beanValueMap.put(beanName.toString(), new HashMap<String, Object>());
- for(MBeanAttributeInfo infoItem : infos)
- {
- Object val = _server.getAttribute(beanName, infoItem.getName());
- // System.out.println(" " + infoItem.getName() + " : " + _server.getAttribute(beanName, infoItem.getName()) + " type : " + infoItem.getType());
- _beanValueMap.get(beanName.toString()).put(infoItem.getName(), val);
- }
- }
- catch (Exception e)
- {
- _logger.error("Error getting bean info, domain="+_domain, e);
- }
- }
-
- @Override
- public void onMBeanUnRegistered(MBeanServerConnection server,
- MBeanServerNotification mbsNotification)
- {
-
- }
- }
- @Test(groups={ "unitTest" })
- public void TestReportData() throws InstanceNotFoundException, MalformedObjectNameException, NullPointerException, IOException, InterruptedException
- {
- System.out.println("START TestParticipantMonitor");
- ParticipantMonitor monitor = new ParticipantMonitor();
-
- int monitorNum = 0;
-
- StateTransitionContext cxt = new StateTransitionContext("cluster", "instance", "db_1","a-b");
- StateTransitionDataPoint data = new StateTransitionDataPoint(1000,1000,true);
- monitor.reportTransitionStat(cxt, data);
-
- data = new StateTransitionDataPoint(1000,1200,true);
- monitor.reportTransitionStat(cxt, data);
-
- ParticipantMonitorListener monitorListener = new ParticipantMonitorListener("CLMParticipantReport");
- Thread.sleep(1000);
- AssertJUnit.assertTrue(monitorListener._beanValueMap.size() == monitorNum + 1);
-
- data = new StateTransitionDataPoint(1000,500,true);
- monitor.reportTransitionStat(cxt, data);
- Thread.sleep(1000);
- AssertJUnit.assertTrue(monitorListener._beanValueMap.size() == monitorNum + 1);
-
- data = new StateTransitionDataPoint(1000,500,true);
- StateTransitionContext cxt2 = new StateTransitionContext("cluster", "instance", "db_2","a-b");
- monitor.reportTransitionStat(cxt2, data);
- monitor.reportTransitionStat(cxt2, data);
- Thread.sleep(1000);
- AssertJUnit.assertTrue(monitorListener._beanValueMap.size() == monitorNum + 2);
-
- AssertJUnit.assertFalse(cxt.equals(cxt2));
- AssertJUnit.assertFalse(cxt.equals(new Object()));
- AssertJUnit.assertTrue(cxt.equals(new StateTransitionContext("cluster", "instance", "db_1","a-b")));
-
- cxt2.getInstanceName();
-
- ParticipantMonitorListener monitorListener2 = new ParticipantMonitorListener("CLMParticipantReport");
-
- Thread.sleep(1000);
- AssertJUnit.assertEquals(monitorListener2._beanValueMap.size() , monitorNum + 2);
-
- monitorListener2.disconnect();
- monitorListener.disconnect();
- System.out.println("END TestParticipantMonitor");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/monitoring/TestStatCollector.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/monitoring/TestStatCollector.java b/helix-core/src/test/java/com/linkedin/helix/monitoring/TestStatCollector.java
deleted file mode 100644
index d720b9a..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/monitoring/TestStatCollector.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.monitoring;
-
-import org.testng.annotations.Test;
-import org.testng.AssertJUnit;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import com.linkedin.helix.monitoring.StatCollector;
-
-public class TestStatCollector
-{
- @Test(groups={ "unitTest" })
- public void TestCollectData()
- {
- StatCollector collector = new StatCollector();
-
- int nPoints = 100;
- for (int i = 0; i< nPoints; i++)
- {
- collector.addData(i*1000);
- }
- AssertJUnit.assertEquals(collector.getNumDataPoints(), nPoints);
- AssertJUnit.assertEquals((long)collector.getMax(), 99000);
- AssertJUnit.assertEquals((long)collector.getTotalSum(), 4950000);
- AssertJUnit.assertEquals((long)collector.getPercentile(40), 39400);
- AssertJUnit.assertEquals((long)collector.getMean(), 49500);
- AssertJUnit.assertEquals((long)collector.getMin(), 0);
-
- collector.reset();
-
- AssertJUnit.assertEquals(collector.getNumDataPoints(), 0);
- AssertJUnit.assertEquals((long)collector.getMax(), 0);
- AssertJUnit.assertEquals((long)collector.getTotalSum(), 0);
- AssertJUnit.assertEquals((long)collector.getPercentile(40), 0);
- AssertJUnit.assertEquals((long)collector.getMean(), 0);
- AssertJUnit.assertEquals((long)collector.getMin(), 0);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/monitoring/mbeans/TestClusterAlertItemMBeanCollection.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/monitoring/mbeans/TestClusterAlertItemMBeanCollection.java b/helix-core/src/test/java/com/linkedin/helix/monitoring/mbeans/TestClusterAlertItemMBeanCollection.java
deleted file mode 100644
index 96e0936..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/monitoring/mbeans/TestClusterAlertItemMBeanCollection.java
+++ /dev/null
@@ -1,255 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.monitoring.mbeans;
-
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.management.AttributeNotFoundException;
-import javax.management.InstanceNotFoundException;
-import javax.management.IntrospectionException;
-import javax.management.MBeanException;
-import javax.management.MalformedObjectNameException;
-import javax.management.ReflectionException;
-
-import org.apache.log4j.Logger;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import com.linkedin.helix.ZNRecord;
-import com.linkedin.helix.alerts.AlertValueAndStatus;
-import com.linkedin.helix.alerts.Tuple;
-import com.linkedin.helix.healthcheck.TestWildcardAlert.TestClusterMBeanObserver;
-import com.linkedin.helix.monitoring.mbeans.ClusterAlertMBeanCollection;
-
-public class TestClusterAlertItemMBeanCollection
-{
- private static final Logger _logger = Logger.getLogger(TestClusterAlertItemMBeanCollection.class);
-
- @Test
- public void TestAlertReportingHistory() throws InstanceNotFoundException, MalformedObjectNameException, NullPointerException, IOException, IntrospectionException, AttributeNotFoundException, ReflectionException, MBeanException
- {
- ClusterAlertMBeanCollection beanCollection = new ClusterAlertMBeanCollection();
-
- String clusterName = "TestCluster";
- String originAlert1 = "EXP(decay(1.0)(esv4-app7*.RestQueryStats@DBName=BizProfile.MinServerLatency))CMP(GREATER)CON(10)";
- Map<String, AlertValueAndStatus> alertResultMap1 = new HashMap<String, AlertValueAndStatus>();
- int nAlerts1 = 5;
-
- String originAlert2 = "EXP(decay(1.0)(esv4-app9*.RestQueryStats@DBName=BizProfile.MaxServerLatency))CMP(GREATER)CON(10)";
- Map<String, AlertValueAndStatus> alertResultMap2 = new HashMap<String, AlertValueAndStatus>();
- int nAlerts2 = 3;
-
- TestClusterMBeanObserver jmxMBeanObserver = new TestClusterMBeanObserver(ClusterAlertMBeanCollection.DOMAIN_ALERT);
-
- for(int i = 0; i < nAlerts1; i++)
- {
- String alertName = "esv4-app7" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName=BizProfile.MinServerLatency";
- Tuple<String> value = new Tuple<String>();
- value.add("22" + i);
- AlertValueAndStatus valueAndStatus = new AlertValueAndStatus(value , true);
- alertResultMap1.put(alertName, valueAndStatus);
- }
-
- for(int i = 0; i < nAlerts2; i++)
- {
- String alertName = "esv4-app9" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName=BizProfile.MaxServerLatency";
- Tuple<String> value = new Tuple<String>();
- value.add("22" + i);
- AlertValueAndStatus valueAndStatus = new AlertValueAndStatus(value , true);
- alertResultMap1.put(alertName, valueAndStatus);
- }
-
- beanCollection.setAlerts(originAlert1, alertResultMap1, clusterName);
- beanCollection.setAlerts(originAlert2, alertResultMap2, clusterName);
-
- beanCollection.refreshAlertDelta(clusterName);
- String summaryKey = ClusterAlertMBeanCollection.ALERT_SUMMARY + "_" + clusterName;
- jmxMBeanObserver.refresh();
-
- // Get the history list
- String beanName = "HelixAlerts:alert=" + summaryKey;
- Map<String, Object> beanValueMap = jmxMBeanObserver._beanValueMap.get(beanName);
- String history1 = (String) (beanValueMap.get("AlertFiredHistory"));
-
- StringReader sr = new StringReader(history1);
- ObjectMapper mapper = new ObjectMapper();
-
- // check the history
-
- Map<String, String> delta = beanCollection.getRecentAlertDelta();
- Assert.assertEquals(delta.size(), nAlerts1 + nAlerts2);
- for(int i = 0; i < nAlerts1; i++)
- {
- String alertBeanName = "(esv4-app7" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName#BizProfile.MinServerLatency)GREATER(10)";
- Assert.assertTrue(delta.get(alertBeanName).equals("ON"));
- }
-
- for(int i = 0; i < nAlerts2; i++)
- {
- String alertBeanName = "(esv4-app9" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName#BizProfile.MaxServerLatency)GREATER(10)";
- Assert.assertTrue(delta.get(alertBeanName).equals("ON"));
- }
-
- alertResultMap1 = new HashMap<String, AlertValueAndStatus>();
- for(int i = 0; i < 3; i++)
- {
- String alertName = "esv4-app7" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName=BizProfile.MinServerLatency";
- Tuple<String> value = new Tuple<String>();
- value.add("22" + i);
- AlertValueAndStatus valueAndStatus = new AlertValueAndStatus(value , true);
- alertResultMap1.put(alertName, valueAndStatus);
- }
-
- for(int i = 3; i < 5; i++)
- {
- String alertName = "esv4-app7" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName=BizProfile.MinServerLatency";
- Tuple<String> value = new Tuple<String>();
- value.add("22" + i);
- AlertValueAndStatus valueAndStatus = new AlertValueAndStatus(value , false);
- alertResultMap1.put(alertName, valueAndStatus);
- }
-
- for(int i = 7; i < 9; i++)
- {
- String alertName = "esv4-app7" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName=BizProfile.MinServerLatency";
- Tuple<String> value = new Tuple<String>();
- value.add("22" + i);
- AlertValueAndStatus valueAndStatus = new AlertValueAndStatus(value , true);
- alertResultMap1.put(alertName, valueAndStatus);
- }
-
- for(int i = 0; i < 2; i++)
- {
- String alertName = "esv4-app9" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName=BizProfile.MaxServerLatency";
- Tuple<String> value = new Tuple<String>();
- value.add("22" + i);
- AlertValueAndStatus valueAndStatus = new AlertValueAndStatus(value , false);
- alertResultMap1.put(alertName, valueAndStatus);
- }
-
- for(int i = 2; i < 3; i++)
- {
- String alertName = "esv4-app9" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName=BizProfile.MaxServerLatency";
- Tuple<String> value = new Tuple<String>();
- value.add("22" + i);
- AlertValueAndStatus valueAndStatus = new AlertValueAndStatus(value , true);
- alertResultMap1.put(alertName, valueAndStatus);
- }
- for(int i = 7; i < 9; i++)
- {
- String alertName = "esv4-app9" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName=BizProfile.MaxServerLatency";
- Tuple<String> value = new Tuple<String>();
- value.add("22" + i);
- AlertValueAndStatus valueAndStatus = new AlertValueAndStatus(value , true);
- alertResultMap1.put(alertName, valueAndStatus);
- }
-
- beanCollection.setAlerts(originAlert1, alertResultMap1, clusterName);
- beanCollection.refreshAlertDelta(clusterName);
- jmxMBeanObserver.refresh();
-
- beanValueMap = jmxMBeanObserver._beanValueMap.get(beanName);
- history1 = (String) (beanValueMap.get("AlertFiredHistory"));
-
- sr = new StringReader(history1);
- mapper = new ObjectMapper();
-
- // check the history
- delta = beanCollection.getRecentAlertDelta();
- Assert.assertEquals(delta.size(), 8);
- for(int i = 3; i < 5; i++)
- {
- String alertBeanName = "(esv4-app7" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName#BizProfile.MinServerLatency)GREATER(10)";
- Assert.assertTrue(delta.get(alertBeanName).equals("OFF"));
- }
- for(int i = 7; i < 9; i++)
- {
- String alertBeanName = "(esv4-app7" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName#BizProfile.MinServerLatency)GREATER(10)";
- Assert.assertTrue(delta.get(alertBeanName).equals("ON"));
- }
-
- for(int i = 0; i < 2; i++)
- {
- String alertBeanName = "(esv4-app9" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName#BizProfile.MaxServerLatency)GREATER(10)";
- Assert.assertTrue(delta.get(alertBeanName).equals("OFF"));
- }
- for(int i = 7; i < 9; i++)
- {
- String alertBeanName = "(esv4-app9" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName#BizProfile.MaxServerLatency)GREATER(10)";
- Assert.assertTrue(delta.get(alertBeanName).equals("ON"));
- }
- }
- @Test
- public void TestAlertRefresh() throws InstanceNotFoundException, MalformedObjectNameException, NullPointerException, IOException, IntrospectionException, AttributeNotFoundException, ReflectionException, MBeanException, InterruptedException
- {
- ClusterAlertMBeanCollection beanCollection = new ClusterAlertMBeanCollection();
-
- String clusterName = "TestCluster";
- String originAlert1 = "EXP(decay(1.0)(esv4-app7*.RestQueryStats@DBName=BizProfile.MinServerLatency))CMP(GREATER)CON(10)";
- Map<String, AlertValueAndStatus> alertResultMap1 = new HashMap<String, AlertValueAndStatus>();
- int nAlerts1 = 5;
-
- String originAlert2 = "EXP(decay(1.0)(esv4-app9*.RestQueryStats@DBName=BizProfile.MaxServerLatency))CMP(GREATER)CON(10)";
- Map<String, AlertValueAndStatus> alertResultMap2 = new HashMap<String, AlertValueAndStatus>();
- int nAlerts2 = 3;
-
- TestClusterMBeanObserver jmxMBeanObserver = new TestClusterMBeanObserver(ClusterAlertMBeanCollection.DOMAIN_ALERT);
-
- for(int i = 0; i < nAlerts1; i++)
- {
- String alertName = "esv4-app7" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName=BizProfile.MinServerLatency";
- Tuple<String> value = new Tuple<String>();
- value.add("22" + i);
- AlertValueAndStatus valueAndStatus = new AlertValueAndStatus(value , true);
- alertResultMap1.put(alertName, valueAndStatus);
- }
-
- for(int i = 0; i < nAlerts2; i++)
- {
- String alertName = "esv4-app9" + i + ".stg.linkedin.com_12918.RestQueryStats@DBName=BizProfile.MaxServerLatency";
- Tuple<String> value = new Tuple<String>();
- value.add("22" + i);
- AlertValueAndStatus valueAndStatus = new AlertValueAndStatus(value , true);
- alertResultMap2.put(alertName, valueAndStatus);
- }
-
- beanCollection.setAlerts(originAlert1, alertResultMap1, clusterName);
- beanCollection.setAlerts(originAlert2, alertResultMap2, clusterName);
-
- beanCollection.refreshAlertDelta(clusterName);
- String summaryKey = ClusterAlertMBeanCollection.ALERT_SUMMARY + "_" + clusterName;
- jmxMBeanObserver.refresh();
-
- Assert.assertEquals(jmxMBeanObserver._beanValueMap.size(), nAlerts2 + nAlerts1 + 1);
-
- Thread.sleep(300);
-
- beanCollection.setAlerts(originAlert1, alertResultMap1, clusterName);
- beanCollection.checkMBeanFreshness(200);
-
- Thread.sleep(500);
-
- jmxMBeanObserver.refresh();
-
- Assert.assertEquals(jmxMBeanObserver._beanValueMap.size(), nAlerts1 + 1);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/monitoring/mbeans/TestClusterStatusMonitor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/monitoring/mbeans/TestClusterStatusMonitor.java b/helix-core/src/test/java/com/linkedin/helix/monitoring/mbeans/TestClusterStatusMonitor.java
deleted file mode 100644
index bce3546..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/monitoring/mbeans/TestClusterStatusMonitor.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.monitoring.mbeans;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.UUID;
-
-import org.testng.annotations.Test;
-
-import com.linkedin.helix.DataAccessor;
-import com.linkedin.helix.HelixDataAccessor;
-import com.linkedin.helix.Mocks;
-import com.linkedin.helix.NotificationContext;
-import com.linkedin.helix.PropertyType;
-import com.linkedin.helix.ZNRecord;
-import com.linkedin.helix.HelixProperty;
-import com.linkedin.helix.model.ExternalView;
-import com.linkedin.helix.model.LiveInstance;
-import com.linkedin.helix.model.LiveInstance.LiveInstanceProperty;
-import com.linkedin.helix.monitoring.mbeans.ClusterStatusMonitor;
-import com.linkedin.helix.tools.IdealStateCalculatorForStorageNode;
-
-
-public class TestClusterStatusMonitor
-{
- List<String> _instances;
- List<ZNRecord> _liveInstances;
- String _db = "DB";
- String _db2 = "TestDB";
- int _replicas = 3;
- int _partitions = 50;
- ZNRecord _externalView, _externalView2;
-
- class MockDataAccessor extends Mocks.MockAccessor
- {
- public MockDataAccessor()
- {
- _instances = new ArrayList<String>();
- for(int i = 0;i < 5; i++)
- {
- String instance = "localhost_"+(12918+i);
- _instances.add(instance);
- }
- ZNRecord externalView = IdealStateCalculatorForStorageNode.calculateIdealState(
- _instances, _partitions, _replicas, _db, "MASTER", "SLAVE");
-
- ZNRecord externalView2 = IdealStateCalculatorForStorageNode.calculateIdealState(
- _instances, 80, 2, _db2, "MASTER", "SLAVE");
-
- }
- public ZNRecord getProperty(PropertyType type, String resource)
- {
- if(type == PropertyType.IDEALSTATES || type == PropertyType.EXTERNALVIEW)
- {
- if(resource.equals(_db))
- {
- return _externalView;
- }
- else if(resource.equals(_db2))
- {
- return _externalView2;
- }
- }
- return null;
- }
- }
- class MockHelixManager extends Mocks.MockManager
- {
- MockDataAccessor _accessor = new MockDataAccessor();
-
- @Override
- public HelixDataAccessor getHelixDataAccessor()
- {
- return _accessor;
- }
-
- }
- @Test()
- public void TestReportData()
- {
- System.out.println("START TestClusterStatusMonitor at" + new Date(System.currentTimeMillis()));
- List<String> _instances;
- List<ZNRecord> _liveInstances = new ArrayList<ZNRecord>();
- String _db = "DB";
- int _replicas = 3;
- int _partitions = 50;
-
- _instances = new ArrayList<String>();
- for(int i = 0;i < 5; i++)
- {
- String instance = "localhost_"+(12918+i);
- _instances.add(instance);
- ZNRecord metaData = new ZNRecord(instance);
- metaData.setSimpleField(LiveInstanceProperty.SESSION_ID.toString(),
- UUID.randomUUID().toString());
- _liveInstances.add(metaData);
- }
- ZNRecord externalView = IdealStateCalculatorForStorageNode.calculateIdealState(
- _instances, _partitions, _replicas, _db, "MASTER", "SLAVE");
-
- ZNRecord externalView2 = IdealStateCalculatorForStorageNode.calculateIdealState(
- _instances, 80, 2, "TestDB", "MASTER", "SLAVE");
-
- List<ZNRecord> externalViews = new ArrayList<ZNRecord>();
- externalViews.add(externalView);
- externalViews.add(externalView2);
-
- ClusterStatusMonitor monitor = new ClusterStatusMonitor("cluster1");
- MockHelixManager manager = new MockHelixManager();
- NotificationContext context = new NotificationContext(manager);
- System.out.println("END TestClusterStatusMonitor at" + new Date(System.currentTimeMillis()));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/monitoring/mbeans/TestResourceMonitor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/monitoring/mbeans/TestResourceMonitor.java b/helix-core/src/test/java/com/linkedin/helix/monitoring/mbeans/TestResourceMonitor.java
deleted file mode 100644
index 92f47f1..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/monitoring/mbeans/TestResourceMonitor.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.monitoring.mbeans;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.testng.AssertJUnit;
-import org.testng.annotations.Test;
-
-import com.linkedin.helix.DataAccessor;
-import com.linkedin.helix.HelixDataAccessor;
-import com.linkedin.helix.HelixProperty;
-import com.linkedin.helix.Mocks;
-import com.linkedin.helix.PropertyKey;
-import com.linkedin.helix.PropertyKey.Builder;
-import com.linkedin.helix.PropertyType;
-import com.linkedin.helix.ZNRecord;
-import com.linkedin.helix.model.ExternalView;
-import com.linkedin.helix.model.IdealState;
-import com.linkedin.helix.model.LiveInstance.LiveInstanceProperty;
-import com.linkedin.helix.monitoring.mbeans.ResourceMonitor;
-import com.linkedin.helix.tools.IdealStateCalculatorForStorageNode;
-
-public class TestResourceMonitor
-{
- String _clusterName = "Test-cluster";
- String _dbName = "TestDB";
- int _replicas = 3;
- int _partitions = 50;
-
- class MockHelixManager extends Mocks.MockManager
- {
- class MockDataAccessor extends Mocks.MockAccessor
- {
- @Override
- public <T extends HelixProperty> List<T> getChildValues(PropertyKey key)
- {
- List<T> result = new ArrayList<T>();
- PropertyType type = key.getType();
- Class<? extends HelixProperty> clazz = key.getTypeClass();
- if (type == PropertyType.EXTERNALVIEW)
- {
- HelixProperty typedInstance = HelixProperty.convertToTypedInstance(clazz, _externalView);
- result.add((T) typedInstance);
- return result;
- }
- else if (type == PropertyType.LIVEINSTANCES)
- {
- return (List<T>) HelixProperty.convertToTypedList(clazz, _liveInstances);
- }
-
- return result;
- }
-
- @Override
- public <T extends HelixProperty> T getProperty(PropertyKey key)
- {
- PropertyType type = key.getType();
- if (type == PropertyType.EXTERNALVIEW)
- {
- return (T) new ExternalView(_externalView);
- }
- else if (type == PropertyType.IDEALSTATES)
- {
- return (T) new IdealState(_idealState);
- }
- return null;
- }
- }
-
- HelixDataAccessor _accessor = new MockDataAccessor();
- ZNRecord _idealState;
- ZNRecord _externalView;
- List<String> _instances;
- List<ZNRecord> _liveInstances;
- String _db = "DB";
-
- public MockHelixManager()
- {
- _liveInstances = new ArrayList<ZNRecord>();
- _instances = new ArrayList<String>();
- for(int i = 0;i<5; i++)
- {
- String instance = "localhost_"+(12918+i);
- _instances.add(instance);
- ZNRecord metaData = new ZNRecord(instance);
- metaData.setSimpleField(LiveInstanceProperty.SESSION_ID.toString(),
- UUID.randomUUID().toString());
-
- }
- _idealState= IdealStateCalculatorForStorageNode.calculateIdealState(_instances,
- _partitions,
- _replicas,
- _dbName,
- "MASTER",
- "SLAVE");
- _externalView = new ZNRecord(_idealState);
- }
-
- @Override
- public HelixDataAccessor getHelixDataAccessor()
- {
- return _accessor;
- }
-
- }
-
- @Test()
- public void TestReportData()
- {
- MockHelixManager manager = new MockHelixManager();
- ResourceMonitor monitor = new ResourceMonitor(_clusterName, _dbName);
-
- HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
- Builder keyBuilder = helixDataAccessor.keyBuilder();
- ExternalView externalView =
- helixDataAccessor.getProperty(keyBuilder.externalView(_dbName));
- IdealState idealState = helixDataAccessor.getProperty(keyBuilder.idealStates(_dbName));
-
- monitor.updateExternalView(externalView, idealState);
-
- AssertJUnit.assertEquals(monitor.getDifferenceWithIdealStateGauge(), 0);
- AssertJUnit.assertEquals(monitor.getErrorPartitionGauge(), 0);
- AssertJUnit.assertEquals(monitor.getExternalViewPartitionGauge(), _partitions);
- AssertJUnit.assertEquals(monitor.getPartitionGauge(), _partitions);
- monitor.getBeanName();
-
- int n = 4;
- for (int i = 0; i < n; i++)
- {
- Map<String, String> map = externalView.getStateMap(_dbName + "_" + 3 * i);
- String key = map.keySet().toArray()[0].toString();
- map.put(key, "ERROR");
- externalView.setStateMap(_dbName + "_" + 3 * i, map);
- }
-
- monitor.updateExternalView(externalView, idealState);
- AssertJUnit.assertEquals(monitor.getDifferenceWithIdealStateGauge(), 0);
- AssertJUnit.assertEquals(monitor.getErrorPartitionGauge(), n);
- AssertJUnit.assertEquals(monitor.getExternalViewPartitionGauge(), _partitions);
- AssertJUnit.assertEquals(monitor.getPartitionGauge(), _partitions);
-
- n = 5;
- for (int i = 0; i < n; i++)
- {
- externalView.getRecord().getMapFields().remove(_dbName + "_" + 4 * i);
- }
-
- monitor.updateExternalView(externalView, idealState);
- AssertJUnit.assertEquals(monitor.getDifferenceWithIdealStateGauge(), n
- * (_replicas + 1));
- AssertJUnit.assertEquals(monitor.getErrorPartitionGauge(), 3);
- AssertJUnit.assertEquals(monitor.getExternalViewPartitionGauge(), _partitions - n);
- AssertJUnit.assertEquals(monitor.getPartitionGauge(), _partitions);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/participant/MockZKHelixManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/participant/MockZKHelixManager.java b/helix-core/src/test/java/com/linkedin/helix/participant/MockZKHelixManager.java
deleted file mode 100644
index 153fef2..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/participant/MockZKHelixManager.java
+++ /dev/null
@@ -1,278 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.participant;
-
-import java.util.UUID;
-
-import com.linkedin.helix.ClusterMessagingService;
-import com.linkedin.helix.ConfigAccessor;
-import com.linkedin.helix.ConfigChangeListener;
-import com.linkedin.helix.ControllerChangeListener;
-import com.linkedin.helix.CurrentStateChangeListener;
-import com.linkedin.helix.DataAccessor;
-import com.linkedin.helix.ExternalViewChangeListener;
-import com.linkedin.helix.HealthStateChangeListener;
-import com.linkedin.helix.HelixAdmin;
-import com.linkedin.helix.HelixDataAccessor;
-import com.linkedin.helix.HelixManager;
-import com.linkedin.helix.IdealStateChangeListener;
-import com.linkedin.helix.InstanceType;
-import com.linkedin.helix.LiveInstanceChangeListener;
-import com.linkedin.helix.MessageListener;
-import com.linkedin.helix.PreConnectCallback;
-import com.linkedin.helix.ZNRecord;
-import com.linkedin.helix.healthcheck.ParticipantHealthReportCollector;
-import com.linkedin.helix.manager.zk.ZKHelixDataAccessor;
-import com.linkedin.helix.manager.zk.ZkBaseDataAccessor;
-import com.linkedin.helix.manager.zk.ZkClient;
-import com.linkedin.helix.store.PropertyStore;
-import com.linkedin.helix.store.zk.ZkHelixPropertyStore;
-
-public class MockZKHelixManager implements HelixManager
-{
- private final ZKHelixDataAccessor _accessor;
- private final String _instanceName;
- private final String _clusterName;
- private final InstanceType _type;
-
- public MockZKHelixManager(String clusterName,
- String instanceName,
- InstanceType type,
- ZkClient zkClient)
- {
- _instanceName = instanceName;
- _clusterName = clusterName;
- _type = type;
- _accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient));
- }
-
- @Override
- public void connect() throws Exception
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean isConnected()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public void disconnect()
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void addIdealStateChangeListener(IdealStateChangeListener listener) throws Exception
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void addLiveInstanceChangeListener(LiveInstanceChangeListener listener) throws Exception
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void addConfigChangeListener(ConfigChangeListener listener) throws Exception
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void addMessageListener(MessageListener listener, String instanceName) throws Exception
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void addCurrentStateChangeListener(CurrentStateChangeListener listener,
- String instanceName,
- String sessionId) throws Exception
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void addExternalViewChangeListener(ExternalViewChangeListener listener) throws Exception
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean removeListener(Object listener)
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public HelixDataAccessor getHelixDataAccessor()
- {
- return _accessor;
- }
-
- @Override
- public String getClusterName()
- {
- return _clusterName;
- }
-
- @Override
- public String getInstanceName()
- {
- return _instanceName;
- }
-
- @Override
- public String getSessionId()
- {
- // TODO Auto-generated method stub
- return UUID.randomUUID().toString();
- }
-
- @Override
- public long getLastNotificationTime()
- {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public void addControllerListener(ControllerChangeListener listener)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public HelixAdmin getClusterManagmentTool()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public PropertyStore<ZNRecord> getPropertyStore()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public ClusterMessagingService getMessagingService()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public ParticipantHealthReportCollector getHealthReportCollector()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public InstanceType getInstanceType()
- {
- return _type;
- }
-
- @Override
- public void addHealthStateChangeListener(HealthStateChangeListener listener,
- String instanceName) throws Exception
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public String getVersion()
- {
- // TODO Auto-generated method stub
- return UUID.randomUUID().toString();
- }
-
- @Override
- public StateMachineEngine getStateMachineEngine()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean isLeader()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public ConfigAccessor getConfigAccessor()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void startTimerTasks()
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void stopTimerTasks()
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public DataAccessor getDataAccessor()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void addPreConnectCallback(PreConnectCallback callback)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public ZkHelixPropertyStore<ZNRecord> getHelixPropertyStore()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/participant/TestDistControllerElection.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/participant/TestDistControllerElection.java b/helix-core/src/test/java/com/linkedin/helix/participant/TestDistControllerElection.java
deleted file mode 100644
index c5683db..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/participant/TestDistControllerElection.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.participant;
-
-import java.util.Date;
-
-import org.apache.log4j.Logger;
-import org.testng.AssertJUnit;
-import org.testng.annotations.Test;
-
-import com.linkedin.helix.HelixManager;
-import com.linkedin.helix.InstanceType;
-import com.linkedin.helix.NotificationContext;
-import com.linkedin.helix.PropertyKey.Builder;
-import com.linkedin.helix.PropertyPathConfig;
-import com.linkedin.helix.PropertyType;
-import com.linkedin.helix.TestHelper;
-import com.linkedin.helix.ZNRecord;
-import com.linkedin.helix.ZkUnitTestBase;
-import com.linkedin.helix.manager.zk.ZKHelixDataAccessor;
-import com.linkedin.helix.manager.zk.ZkBaseDataAccessor;
-import com.linkedin.helix.model.LiveInstance;
-
-public class TestDistControllerElection extends ZkUnitTestBase
-{
- private static Logger LOG = Logger.getLogger(TestDistControllerElection.class);
-
- @Test()
- public void testController() throws Exception
- {
- System.out.println("START TestDistControllerElection at "
- + new Date(System.currentTimeMillis()));
- String className = getShortClassName();
-
- final String clusterName = CLUSTER_PREFIX + "_" + className + "_" + "testController";
- String path = "/" + clusterName;
- if (_gZkClient.exists(path))
- {
- _gZkClient.deleteRecursive(path);
- }
-
- ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
- Builder keyBuilder = accessor.keyBuilder();
-
- TestHelper.setupEmptyCluster(_gZkClient, clusterName);
-
- final String controllerName = "controller_0";
- HelixManager manager = new MockZKHelixManager(clusterName, controllerName,
- InstanceType.CONTROLLER,
- _gZkClient);
-
- DistClusterControllerElection election = new DistClusterControllerElection(ZK_ADDR);
- NotificationContext context = new NotificationContext(manager);
- context.setType(NotificationContext.Type.INIT);
- election.onControllerChange(context);
-
-// path = PropertyPathConfig.getPath(PropertyType.LEADER, clusterName);
-// ZNRecord leaderRecord = _gZkClient.<ZNRecord> readData(path);
- LiveInstance liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
- AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
- // AssertJUnit.assertNotNull(election.getController());
- // AssertJUnit.assertNull(election.getLeader());
-
- manager = new MockZKHelixManager(clusterName, "controller_1", InstanceType.CONTROLLER,
- _gZkClient);
- election = new DistClusterControllerElection(ZK_ADDR);
- context = new NotificationContext(manager);
- context.setType(NotificationContext.Type.INIT);
- election.onControllerChange(context);
-// leaderRecord = _gZkClient.<ZNRecord> readData(path);
- liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
- AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
- // AssertJUnit.assertNull(election.getController());
- // AssertJUnit.assertNull(election.getLeader());
-
- System.out.println("END TestDistControllerElection at " + new Date(System.currentTimeMillis()));
- }
-
- @Test()
- public void testControllerParticipant() throws Exception
- {
- String className = getShortClassName();
- LOG.info("RUN " + className + " at " + new Date(System.currentTimeMillis()));
-
- final String clusterName = CONTROLLER_CLUSTER_PREFIX + "_" + className + "_"
- + "testControllerParticipant";
- String path = "/" + clusterName;
- if (_gZkClient.exists(path))
- {
- _gZkClient.deleteRecursive(path);
- }
-
- ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
- Builder keyBuilder = accessor.keyBuilder();
-
- TestHelper.setupEmptyCluster(_gZkClient, clusterName);
-
- final String controllerName = "controller_0";
- HelixManager manager = new MockZKHelixManager(clusterName, controllerName,
- InstanceType.CONTROLLER_PARTICIPANT,
- _gZkClient);
-
- DistClusterControllerElection election = new DistClusterControllerElection(ZK_ADDR);
- NotificationContext context = new NotificationContext(manager);
- context.setType(NotificationContext.Type.CALLBACK);
- election.onControllerChange(context);
-
- LiveInstance liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
- AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
-
-// path = PropertyPathConfig.getPath(PropertyType.LEADER, clusterName);
-// ZNRecord leaderRecord = _gZkClient.<ZNRecord> readData(path);
-// AssertJUnit.assertEquals(controllerName, leaderRecord.getSimpleField("LEADER"));
- // AssertJUnit.assertNotNull(election.getController());
- // AssertJUnit.assertNotNull(election.getLeader());
-
- manager = new MockZKHelixManager(clusterName, "controller_1",
- InstanceType.CONTROLLER_PARTICIPANT,
- _gZkClient);
- election = new DistClusterControllerElection(ZK_ADDR);
- context = new NotificationContext(manager);
- context.setType(NotificationContext.Type.CALLBACK);
- election.onControllerChange(context);
-
- liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
- AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
-
-// leaderRecord = _gZkClient.<ZNRecord> readData(path);
-// AssertJUnit.assertEquals(controllerName, leaderRecord.getSimpleField("LEADER"));
- // AssertJUnit.assertNull(election.getController());
- // AssertJUnit.assertNull(election.getLeader());
-
- LOG.info("END " + getShortClassName() + " at " + new Date(System.currentTimeMillis()));
- }
-
- @Test()
- public void testParticipant() throws Exception
- {
- String className = getShortClassName();
- LOG.info("RUN " + className + " at " + new Date(System.currentTimeMillis()));
-
- final String clusterName = CLUSTER_PREFIX + "_" + className + "_" + "testParticipant";
- String path = "/" + clusterName;
- if (_gZkClient.exists(path))
- {
- _gZkClient.deleteRecursive(path);
- }
- TestHelper.setupEmptyCluster(_gZkClient, clusterName);
-
- final String controllerName = "participant_0";
- HelixManager manager = new MockZKHelixManager(clusterName, controllerName,
- InstanceType.PARTICIPANT,
- _gZkClient);
-
- DistClusterControllerElection election = new DistClusterControllerElection(ZK_ADDR);
- NotificationContext context = new NotificationContext(manager);
- context.setType(NotificationContext.Type.INIT);
- election.onControllerChange(context);
-
- path = PropertyPathConfig.getPath(PropertyType.LEADER, clusterName);
- ZNRecord leaderRecord = _gZkClient.<ZNRecord> readData(path, true);
- AssertJUnit.assertNull(leaderRecord);
- // AssertJUnit.assertNull(election.getController());
- // AssertJUnit.assertNull(election.getLeader());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/participant/TestDistControllerStateModel.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/participant/TestDistControllerStateModel.java b/helix-core/src/test/java/com/linkedin/helix/participant/TestDistControllerStateModel.java
deleted file mode 100644
index d06798c..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/participant/TestDistControllerStateModel.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.participant;
-
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.linkedin.helix.NotificationContext;
-import com.linkedin.helix.TestHelper;
-import com.linkedin.helix.ZkUnitTestBase;
-import com.linkedin.helix.model.Message;
-import com.linkedin.helix.model.Message.MessageType;
-
-public class TestDistControllerStateModel extends ZkUnitTestBase
-{
- final String clusterName = CLUSTER_PREFIX + "_" + getShortClassName();
- DistClusterControllerStateModel stateModel = null;
-
- @BeforeMethod()
- public void beforeMethod()
- {
- stateModel = new DistClusterControllerStateModel(ZK_ADDR);
- if (_gZkClient.exists("/" + clusterName))
- {
- _gZkClient.deleteRecursive("/" + clusterName);
- }
- TestHelper.setupEmptyCluster(_gZkClient, clusterName);
- }
-
- @Test()
- public void testOnBecomeStandbyFromOffline()
- {
- stateModel.onBecomeStandbyFromOffline(null, null);
- }
-
- @Test()
- public void testOnBecomeLeaderFromStandby()
- {
- Message message = new Message(MessageType.STATE_TRANSITION, "0");
- message.setPartitionName(clusterName);
- message.setTgtName("controller_0");
- try
- {
- stateModel.onBecomeLeaderFromStandby(message, new NotificationContext(null));
- }
- catch (Exception e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- stateModel.onBecomeStandbyFromLeader(message, new NotificationContext(null));
- }
-
- @Test()
- public void testOnBecomeStandbyFromLeader()
- {
- Message message = new Message(MessageType.STATE_TRANSITION, "0");
- message.setPartitionName(clusterName);
- message.setTgtName("controller_0");
- stateModel.onBecomeStandbyFromLeader(message, new NotificationContext(null));
- }
-
- @Test()
- public void testOnBecomeOfflineFromStandby()
- {
- Message message = new Message(MessageType.STATE_TRANSITION, "0");
- message.setPartitionName(clusterName);
- message.setTgtName("controller_0");
-
- stateModel.onBecomeOfflineFromStandby(message, null);
- }
-
- @Test()
- public void testOnBecomeDroppedFromOffline()
- {
- stateModel.onBecomeDroppedFromOffline(null, null);
- }
-
- @Test()
- public void testOnBecomeOfflineFromDropped()
- {
- stateModel.onBecomeOfflineFromDropped(null, null);
- }
-
- @Test()
- public void testRollbackOnError()
- {
- Message message = new Message(MessageType.STATE_TRANSITION, "0");
- message.setPartitionName(clusterName);
- message.setTgtName("controller_0");
- try
- {
- stateModel.onBecomeLeaderFromStandby(message, new NotificationContext(null));
- }
- catch (Exception e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- stateModel.rollbackOnError(message, new NotificationContext(null), null);
- }
-
- @Test()
- public void testReset()
- {
- Message message = new Message(MessageType.STATE_TRANSITION, "0");
- message.setPartitionName(clusterName);
- message.setTgtName("controller_0");
- try
- {
- stateModel.onBecomeLeaderFromStandby(message, new NotificationContext(null));
- }
- catch (Exception e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- stateModel.reset();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/participant/TestDistControllerStateModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/participant/TestDistControllerStateModelFactory.java b/helix-core/src/test/java/com/linkedin/helix/participant/TestDistControllerStateModelFactory.java
deleted file mode 100644
index ef424b5..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/participant/TestDistControllerStateModelFactory.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.participant;
-
-import org.testng.annotations.Test;
-import org.testng.annotations.Test;
-
-import com.linkedin.helix.ZkUnitTestBase;
-import com.linkedin.helix.participant.DistClusterControllerStateModel;
-import com.linkedin.helix.participant.DistClusterControllerStateModelFactory;
-
-public class TestDistControllerStateModelFactory
-{
- final String zkAddr = ZkUnitTestBase.ZK_ADDR;
-
- @Test(groups = { "unitTest" })
- public void testDistControllerStateModelFactory()
- {
- DistClusterControllerStateModelFactory factory = new DistClusterControllerStateModelFactory(zkAddr);
- DistClusterControllerStateModel stateModel = factory.createNewStateModel("key");
- stateModel.onBecomeStandbyFromOffline(null, null);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/3cb7a1c9/helix-core/src/test/java/com/linkedin/helix/store/TestJsonComparator.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/com/linkedin/helix/store/TestJsonComparator.java b/helix-core/src/test/java/com/linkedin/helix/store/TestJsonComparator.java
deleted file mode 100644
index d26a90e..0000000
--- a/helix-core/src/test/java/com/linkedin/helix/store/TestJsonComparator.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Copyright (C) 2012 LinkedIn Inc <op...@linkedin.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.linkedin.helix.store;
-
-import java.util.Date;
-
-import org.testng.AssertJUnit;
-import org.testng.annotations.Test;
-
-import com.linkedin.helix.ZNRecord;
-import com.linkedin.helix.store.PropertyJsonComparator;
-
-public class TestJsonComparator
-{
- @Test (groups = {"unitTest"})
- public void testJsonComparator()
- {
- System.out.println("START TestJsonComparator at " + new Date(System.currentTimeMillis()));
-
- ZNRecord record = new ZNRecord("id1");
- PropertyJsonComparator<ZNRecord> comparator = new PropertyJsonComparator<ZNRecord>(ZNRecord.class);
- AssertJUnit.assertTrue(comparator.compare(null, null) == 0);
- AssertJUnit.assertTrue(comparator.compare(null, record) == -1);
- AssertJUnit.assertTrue(comparator.compare(record, null) == 1);
- System.out.println("END TestJsonComparator at " + new Date(System.currentTimeMillis()));
- }
-}