narendly commented on a change in pull request #788: Implement request 
forwarding for ZkRoutingDataWriter
URL: https://github.com/apache/helix/pull/788#discussion_r384773327
 
 

 ##########
 File path: 
helix-rest/src/test/java/org/apache/helix/rest/server/MetadataStoreDirectoryAccessorTestBase.java
 ##########
 @@ -0,0 +1,128 @@
+package org.apache.helix.rest.server;
+
+/*
+ * 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.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.helix.TestHelper;
+import org.apache.helix.msdcommon.constant.MetadataStoreRoutingConstants;
+import org.apache.helix.msdcommon.exception.InvalidRoutingDataException;
+import 
org.apache.helix.rest.metadatastore.accessor.MetadataStoreRoutingDataReader;
+import org.apache.helix.rest.metadatastore.accessor.ZkRoutingDataReader;
+import org.apache.helix.zookeeper.datamodel.ZNRecord;
+import org.apache.helix.zookeeper.datamodel.serializer.ZNRecordSerializer;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+
+
+public class MetadataStoreDirectoryAccessorTestBase extends AbstractTestClass {
+  /*
+   * The following are constants to be used for testing.
+   */
+  protected static final String TEST_NAMESPACE_URI_PREFIX = "/namespaces/" + 
TEST_NAMESPACE;
+  protected static final String NON_EXISTING_NAMESPACE_URI_PREFIX =
+      "/namespaces/not-existed-namespace/metadata-store-realms/";
+  protected static final String TEST_REALM_1 = "testRealm1";
+  protected static final List<String> TEST_SHARDING_KEYS_1 =
+      Arrays.asList("/sharding/key/1/a", "/sharding/key/1/b", 
"/sharding/key/1/c");
+  protected static final String TEST_REALM_2 = "testRealm2";
+  protected static final List<String> TEST_SHARDING_KEYS_2 =
+      Arrays.asList("/sharding/key/1/d", "/sharding/key/1/e", 
"/sharding/key/1/f");
+  protected static final String TEST_REALM_3 = "testRealm3";
+  protected static final String TEST_SHARDING_KEY = "/sharding/key/1/x";
+
+  // List of all ZK addresses, each of which corresponds to a 
namespace/routing ZK
+  protected List<String> _zkList;
+  protected MetadataStoreRoutingDataReader _routingDataReader;
+
+  @BeforeClass
+  public void beforeClass() throws Exception {
+    _zkList = new ArrayList<>(ZK_SERVER_MAP.keySet());
+
+    deleteRoutingDataPath();
+
+    // Write dummy mappings in ZK
+    // Create a node that represents a realm address and add 3 sharding keys 
to it
+    ZNRecord znRecord = new ZNRecord("RoutingInfo");
+
+    _zkList.forEach(zk -> {
+      ZK_SERVER_MAP.get(zk).getZkClient().setZkSerializer(new 
ZNRecordSerializer());
+      // Write first realm and sharding keys pair
+      
znRecord.setListField(MetadataStoreRoutingConstants.ZNRECORD_LIST_FIELD_KEY,
+          TEST_SHARDING_KEYS_1);
+      ZK_SERVER_MAP.get(zk).getZkClient()
+          .createPersistent(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + 
"/" + TEST_REALM_1,
+              true);
+      ZK_SERVER_MAP.get(zk).getZkClient()
+          .writeData(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/" + 
TEST_REALM_1,
+              znRecord);
+
+      // Create another realm and sharding keys pair
+      
znRecord.setListField(MetadataStoreRoutingConstants.ZNRECORD_LIST_FIELD_KEY,
+          TEST_SHARDING_KEYS_2);
+      ZK_SERVER_MAP.get(zk).getZkClient()
+          .createPersistent(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + 
"/" + TEST_REALM_2,
+              true);
+      ZK_SERVER_MAP.get(zk).getZkClient()
+          .writeData(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/" + 
TEST_REALM_2,
+              znRecord);
+    });
+
+    _routingDataReader = new ZkRoutingDataReader(TEST_NAMESPACE, 
_zkAddrTestNS, null);
+
+    System.setProperty(MetadataStoreRoutingConstants.MSDS_SERVER_HOSTNAME_KEY,
+        getBaseUri().toString());
+  }
+
+  @AfterClass
+  public void afterClass() throws Exception {
+    
System.clearProperty(MetadataStoreRoutingConstants.MSDS_SERVER_HOSTNAME_KEY);
+    deleteRoutingDataPath();
+  }
+
+  protected void deleteRoutingDataPath() throws Exception {
+    Assert.assertTrue(TestHelper.verify(() -> {
+      _zkList.forEach(zk -> ZK_SERVER_MAP.get(zk).getZkClient()
+          .deleteRecursively(MetadataStoreRoutingConstants.ROUTING_DATA_PATH));
+
+      for (String zk : _zkList) {
+        if (ZK_SERVER_MAP.get(zk).getZkClient()
+            .exists(MetadataStoreRoutingConstants.ROUTING_DATA_PATH)) {
+          return false;
+        }
+      }
+
+      return true;
+    }, TestHelper.WAIT_DURATION), "Routing data path should be deleted after 
the tests.");
+  }
+
+  protected Set<String> getAllMetadataStoreRealmsHelper() throws 
InvalidRoutingDataException {
+    return new HashSet<>(_routingDataReader.getRoutingData().keySet());
 
 Review comment:
   getAllMetadataStoreRealmsHelper -> this naming is a little confusing. 
Consider renaming or explain what it does and why it's needed.

----------------------------------------------------------------
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]

Reply via email to