li4wang commented on code in PR #2320:
URL: https://github.com/apache/zookeeper/pull/2320#discussion_r2696837071


##########
zookeeper-server/src/test/java/org/apache/zookeeper/client/DnsSrvHostProviderTest.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.
+ */
+
+package org.apache.zookeeper.client;
+
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.net.InetSocketAddress;
+import org.apache.zookeeper.client.DnsSrvHostProvider.DnsSrvResolver;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.xbill.DNS.Name;
+import org.xbill.DNS.SRVRecord;
+
+public class DnsSrvHostProviderTest {
+
+    private static final String TEST_DNS_NAME = "_zookeeper._tcp.example.com.";
+    private static final long TEST_SEED = 12345L;
+
+    private DnsSrvResolver mockDnsSrvResolver;
+
+    @BeforeEach
+    public void setUp() {
+        mockDnsSrvResolver = mock(DnsSrvResolver.class);
+    }
+
+    @AfterEach
+    public void tearDown() {
+        System.clearProperty(ZKClientConfig.DNS_SRV_REFRESH_INTERVAL_SECONDS);
+    }
+
+    @Test
+    public void testBasic() throws Exception {
+        final SRVRecord[] srvRecords = createMockSrvRecords();
+        
when(mockDnsSrvResolver.lookupSrvRecords(TEST_DNS_NAME)).thenReturn(srvRecords);
+
+        try (final DnsSrvHostProvider hostProvider = new 
DnsSrvHostProvider(TEST_DNS_NAME, TEST_SEED, mockDnsSrvResolver, null)) {
+            assertEquals(3, hostProvider.size());
+            assertNotNull(hostProvider.next(0));
+        }
+    }
+
+    @Test
+    public void testServerIteration() throws Exception {
+        final SRVRecord[] srvRecords = createMockSrvRecords();
+        
when(mockDnsSrvResolver.lookupSrvRecords(TEST_DNS_NAME)).thenReturn(srvRecords);
+
+        try (final DnsSrvHostProvider hostProvider = new 
DnsSrvHostProvider(TEST_DNS_NAME, TEST_SEED, mockDnsSrvResolver, null)) {
+            final InetSocketAddress addr1 = hostProvider.next(0);
+            final InetSocketAddress addr2 = hostProvider.next(0);
+            final InetSocketAddress addr3 = hostProvider.next(0);
+
+            assertNotNull(addr1);
+            assertNotNull(addr2);
+            assertNotNull(addr3);

Review Comment:
   updated



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to