narendly commented on a change in pull request #789: Add FederatedZkClient URL: https://github.com/apache/helix/pull/789#discussion_r382954074
########## File path: zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/client/TestFederatedZkClient.java ########## @@ -0,0 +1,310 @@ +package org.apache.helix.zookeeper.impl.client; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.concurrent.TimeUnit; + +import org.apache.helix.msdcommon.datamodel.TrieRoutingData; +import org.apache.helix.msdcommon.exception.InvalidRoutingDataException; +import org.apache.helix.zookeeper.api.client.RealmAwareZkClient; +import org.apache.helix.zookeeper.datamodel.ZNRecord; +import org.apache.helix.zookeeper.datamodel.serializer.ZNRecordSerializer; +import org.apache.helix.zookeeper.impl.ZkTestBase; +import org.apache.helix.zookeeper.zkclient.IZkStateListener; +import org.apache.helix.zookeeper.zkclient.ZkServer; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.Op; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooDefs; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +public class TestFederatedZkClient extends ZkTestBase { + private static final String TEST_SHARDING_KEY_PREFIX = "/test_sharding_key_"; + private static final String TEST_REALM_ONE_VALID_PATH = TEST_SHARDING_KEY_PREFIX + "1/a/b/c"; + private static final String TEST_REALM_TWO_VALID_PATH = TEST_SHARDING_KEY_PREFIX + "2/x/y/z"; + private static final String TEST_INVALID_PATH = TEST_SHARDING_KEY_PREFIX + "invalid/a/b/c"; + private static final String UNSUPPORTED_OPERATION_MESSAGE = + "Session-aware operation is not supported by FederatedZkClient."; + + private RealmAwareZkClient _realmAwareZkClient; + // Need to start an extra ZK server for multi-realm test, if only one ZK server is running. + private String _extraZkRealm; + private ZkServer _extraZkServer; + + @BeforeClass + public void beforeClass() throws InvalidRoutingDataException { + System.out.println("Starting " + TestFederatedZkClient.class.getSimpleName()); + + // Populate rawRoutingData + // <Realm, List of sharding keys> Mapping + Map<String, List<String>> rawRoutingData = new HashMap<>(); + for (int i = 0; i < _numZk; i++) { + List<String> shardingKeyList = Collections.singletonList(TEST_SHARDING_KEY_PREFIX + (i + 1)); + String realmName = ZK_PREFIX + (ZK_START_PORT + i); + rawRoutingData.put(realmName, shardingKeyList); + } + + if (rawRoutingData.size() < 2) { + System.out.println("There is only one ZK realm. Starting one more ZK to test multi-realm."); + _extraZkRealm = ZK_PREFIX + (ZK_START_PORT + 1); + _extraZkServer = startZkServer(_extraZkRealm); + // RealmTwo's sharding key: /test_sharding_key_2 + List<String> shardingKeyList = Collections.singletonList(TEST_SHARDING_KEY_PREFIX + "2"); + rawRoutingData.put(_extraZkRealm, shardingKeyList); + } Review comment: This is not necessary when the tests are being run by maven's surefire-plugin (what runs your mvn test's). Writing this block of code would be just for IntelliJ, so I wouldn't bother creating logic like this in your future tests. You can have 2 or more ZKs in your tests, but we have two runs for a reason - we want to test it in a single ZK environment and also test it in a multi-ZK environment. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
