frankgh commented on code in PR #193:
URL: https://github.com/apache/cassandra-sidecar/pull/193#discussion_r1980285723


##########
server/src/test/java/org/apache/cassandra/sidecar/cdc/CdcConfigImplTest.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * 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.cassandra.sidecar.cdc;
+
+import java.util.Map;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import io.vertx.core.Promise;
+import io.vertx.core.Vertx;
+import org.apache.cassandra.sidecar.TestResourceReaper;
+import org.apache.cassandra.sidecar.common.server.ThrowingRunnable;
+import 
org.apache.cassandra.sidecar.common.server.utils.MillisecondBoundConfiguration;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.config.CdcConfiguration;
+import org.apache.cassandra.sidecar.config.SchemaKeyspaceConfiguration;
+import org.apache.cassandra.sidecar.config.yaml.ServiceConfigurationImpl;
+import org.apache.cassandra.sidecar.coordination.ClusterLease;
+import org.apache.cassandra.sidecar.db.CdcConfigAccessor;
+import org.apache.cassandra.sidecar.db.KafkaConfigAccessor;
+import org.apache.cassandra.sidecar.tasks.PeriodicTaskExecutor;
+import org.apache.cassandra.sidecar.tasks.ScheduleDecision;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class CdcConfigImplTest
+{
+    private static final Vertx vertx = Vertx.vertx();
+    private static final ExecutorPools executorPools = new 
ExecutorPools(vertx, new ServiceConfigurationImpl());
+    private static final ClusterLease clusterLease = new ClusterLease();
+    private PeriodicTaskExecutor executor = new 
PeriodicTaskExecutor(executorPools, clusterLease);
+
+    @BeforeEach
+    void beforeEach()
+    {
+        executor = new PeriodicTaskExecutor(executorPools, clusterLease);
+    }
+
+    @AfterEach
+    void afterEach()
+    {
+        clusterLease.setOwnershipTesting(ClusterLease.Ownership.INDETERMINATE);
+        executor.close(Promise.promise());
+    }
+
+    @AfterAll
+    static void teardown()
+    {
+        TestResourceReaper.create().with(vertx).with(executorPools).close();
+    }
+
+    @Test
+    void testIsConfigReadySchemaNotInitialized()
+    {
+        CdcConfigAccessor cdcConfigAccessor = mockCdcConfigAccessor();
+        KafkaConfigAccessor kafkaConfigAccessor = mockKafkaConfigAccessor();
+        when(cdcConfigAccessor.isSchemaInitialized()).thenReturn(false);
+
+        CdcConfigImpl cdcConfig =
+                new CdcConfigImpl(mockCdcConfiguration(), 
mockSchemaKeyspaceConfiguration(), cdcConfigAccessor, kafkaConfigAccessor, 
executor);
+        assertThat(cdcConfig.isConfigReady()).isFalse();
+    }
+
+    @Test
+    void testIsConfigReadyKafkaConfigsEmpty()
+    {
+        CdcConfigAccessor cdcConfigAccessor = mockCdcConfigAccessor();
+        KafkaConfigAccessor kafkaConfigAccessor = mockKafkaConfigAccessor();
+        
when(cdcConfigAccessor.getConfig().getConfigs()).thenReturn(Map.of("k1", "v1"));
+        CdcConfigImpl cdcConfig =
+                new CdcConfigImpl(mockCdcConfiguration(), 
mockSchemaKeyspaceConfiguration(), cdcConfigAccessor, kafkaConfigAccessor, 
executor);
+        assertThat(cdcConfig.isConfigReady()).isFalse();
+    }
+
+    @Test
+    void testIsConfigReadyCdcConfigsEmpty()
+    {
+        CdcConfigAccessor cdcConfigAccessor = mockCdcConfigAccessor();
+        KafkaConfigAccessor kafkaConfigAccessor = mockKafkaConfigAccessor();
+        
when(cdcConfigAccessor.getConfig().getConfigs()).thenReturn(Map.of("k1", "v1"));
+        CdcConfigImpl cdcConfig =
+                new CdcConfigImpl(mockCdcConfiguration(), 
mockSchemaKeyspaceConfiguration(), cdcConfigAccessor, kafkaConfigAccessor, 
executor);
+        assertThat(cdcConfig.isConfigReady()).isFalse();
+    }
+
+    @Test
+    void testReturnDefaultValuesWhenConfigsAreEmpty()
+    {
+        CdcConfigAccessor cdcConfigAccessor = mockCdcConfigAccessor();
+        KafkaConfigAccessor kafkaConfigAccessor = mockKafkaConfigAccessor();
+        CdcConfigImpl cdcConfig =
+                new CdcConfigImpl(mockCdcConfiguration(), 
mockSchemaKeyspaceConfiguration(), cdcConfigAccessor, kafkaConfigAccessor, 
executor);
+        assertThat(cdcConfig.dc()).isEqualTo(null);
+        assertThat(cdcConfig.env()).isEqualTo("");
+        assertThat(cdcConfig.kafkaTopic()).isNull();
+        assertThat(cdcConfig.logOnly()).isFalse();
+    }
+
+    @Test
+    void testConfigsWhenConfigsAreNotEmpty() throws InterruptedException
+    {
+        CdcConfigAccessor cdcConfigAccessor = mockCdcConfigAccessor();
+        KafkaConfigAccessor kafkaConfigAccessor = mockKafkaConfigAccessor();
+        when(cdcConfigAccessor.getConfig().getConfigs())
+                .thenReturn(Map.of("dc", "DC1", "env", "if", "log_only", 
"false", "topic", "topic1"));
+        when(kafkaConfigAccessor.getConfig().getConfigs())
+                .thenReturn(Map.of("k1", "v1"));
+
+        CdcConfigImpl cdcConfig =
+                new CdcConfigImpl(mockCdcConfiguration(), 
mockSchemaKeyspaceConfiguration(), cdcConfigAccessor, kafkaConfigAccessor, 
executor);
+        while (!cdcConfig.isConfigReady())
+        {
+            Thread.sleep(1000);
+        }

Review Comment:
   NIT:
   ```suggestion
           loopAssert(5000, ()-> 
assertThat(cdcConfig.isConfigReady()).isTrue());
   ```



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to