Re: [PR] KAFKA-15570: Add unit tests for MemoryConfigBackingStore [kafka]

2023-10-12 Thread via GitHub


yashmayya merged PR #14518:
URL: https://github.com/apache/kafka/pull/14518


-- 
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: jira-unsubscr...@kafka.apache.org

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



Re: [PR] KAFKA-15570: Add unit tests for MemoryConfigBackingStore [kafka]

2023-10-12 Thread via GitHub


yashmayya commented on PR #14518:
URL: https://github.com/apache/kafka/pull/14518#issuecomment-1759205904

   Test failures are unrelated, merging to `trunk`.


-- 
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: jira-unsubscr...@kafka.apache.org

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



Re: [PR] KAFKA-15570: Add unit tests for MemoryConfigBackingStore [kafka]

2023-10-11 Thread via GitHub


yashmayya commented on code in PR #14518:
URL: https://github.com/apache/kafka/pull/14518#discussion_r1356053586


##
connect/runtime/src/test/java/org/apache/kafka/connect/storage/MemoryConfigBackingStoreTest.java:
##
@@ -0,0 +1,183 @@
+/*
+ * 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.kafka.connect.storage;
+
+import org.apache.kafka.connect.runtime.TargetState;
+import org.apache.kafka.connect.util.ConnectorTaskId;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anySet;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class MemoryConfigBackingStoreTest {
+
+private static final List CONNECTOR_IDS = 
Arrays.asList("connector1", "connector2");
+
+// Actual values are irrelevant here and can be used as either connector 
or task configurations
+private static final List> SAMPLE_CONFIGS = 
Arrays.asList(
+Collections.singletonMap("config-key-one", "config-value-one"),
+Collections.singletonMap("config-key-two", "config-value-two"),
+Collections.singletonMap("config-key-three", "config-value-three")
+);
+
+@Mock
+private ConfigBackingStore.UpdateListener configUpdateListener;
+private final MemoryConfigBackingStore configStore = new 
MemoryConfigBackingStore();
+
+@Before
+public void setUp() {
+configStore.setUpdateListener(configUpdateListener);
+}
+
+@Test
+public void testPutConnectorConfig() {
+configStore.putConnectorConfig(CONNECTOR_IDS.get(0), 
SAMPLE_CONFIGS.get(0));
+ClusterConfigState configState = configStore.snapshot();
+
+assertTrue(configState.contains(CONNECTOR_IDS.get(0)));
+// Default initial target state of STARTED should be used if no 
explicit target state is specified
+assertEquals(TargetState.STARTED, 
configState.targetState(CONNECTOR_IDS.get(0)));
+assertEquals(SAMPLE_CONFIGS.get(0), 
configState.connectorConfig(CONNECTOR_IDS.get(0)));
+assertEquals(1, configState.connectors().size());
+
+
verify(configUpdateListener).onConnectorConfigUpdate(eq(CONNECTOR_IDS.get(0)));
+}
+
+@Test
+public void testPutConnectorConfigUpdateExisting() {
+configStore.putConnectorConfig(CONNECTOR_IDS.get(0), 
SAMPLE_CONFIGS.get(0));
+ClusterConfigState configState = configStore.snapshot();
+
+assertTrue(configState.contains(CONNECTOR_IDS.get(0)));
+// Default initial target state of STARTED should be used if no 
explicit target state is specified
+assertEquals(TargetState.STARTED, 
configState.targetState(CONNECTOR_IDS.get(0)));
+assertEquals(SAMPLE_CONFIGS.get(0), 
configState.connectorConfig(CONNECTOR_IDS.get(0)));
+assertEquals(1, configState.connectors().size());
+
+configStore.putConnectorConfig(CONNECTOR_IDS.get(0), 
SAMPLE_CONFIGS.get(1));
+configState = configStore.snapshot();
+assertEquals(SAMPLE_CONFIGS.get(1), 
configState.connectorConfig(CONNECTOR_IDS.get(0)));
+
+verify(configUpdateListener, 
times(2)).onConnectorConfigUpdate(eq(CONNECTOR_IDS.get(0)));
+}
+
+@Test
+public void testRemoveConnectorConfig() {
+configStore.putConnectorConfig(CONNECTOR_IDS.get(0), 
SAMPLE_CONFIGS.get(0));
+configStore.putConnectorConfig(CONNECTOR_IDS.get(1), 
SAMPLE_CONFIGS.get(1));
+ClusterConfigState configState = configStore.snapshot();
+
+assertTrue(configState.contains(CONNECTOR_IDS.get(0)));
+

Re: [PR] KAFKA-15570: Add unit tests for MemoryConfigBackingStore [kafka]

2023-10-11 Thread via GitHub


C0urante commented on code in PR #14518:
URL: https://github.com/apache/kafka/pull/14518#discussion_r1355538647


##
connect/runtime/src/test/java/org/apache/kafka/connect/storage/MemoryConfigBackingStoreTest.java:
##
@@ -0,0 +1,183 @@
+/*
+ * 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.kafka.connect.storage;
+
+import org.apache.kafka.connect.runtime.TargetState;
+import org.apache.kafka.connect.util.ConnectorTaskId;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anySet;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class MemoryConfigBackingStoreTest {
+
+private static final List CONNECTOR_IDS = 
Arrays.asList("connector1", "connector2");
+
+// Actual values are irrelevant here and can be used as either connector 
or task configurations
+private static final List> SAMPLE_CONFIGS = 
Arrays.asList(
+Collections.singletonMap("config-key-one", "config-value-one"),
+Collections.singletonMap("config-key-two", "config-value-two"),
+Collections.singletonMap("config-key-three", "config-value-three")
+);
+
+@Mock
+private ConfigBackingStore.UpdateListener configUpdateListener;
+private final MemoryConfigBackingStore configStore = new 
MemoryConfigBackingStore();
+
+@Before
+public void setUp() {
+configStore.setUpdateListener(configUpdateListener);
+}
+
+@Test
+public void testPutConnectorConfig() {
+configStore.putConnectorConfig(CONNECTOR_IDS.get(0), 
SAMPLE_CONFIGS.get(0));
+ClusterConfigState configState = configStore.snapshot();
+
+assertTrue(configState.contains(CONNECTOR_IDS.get(0)));
+// Default initial target state of STARTED should be used if no 
explicit target state is specified
+assertEquals(TargetState.STARTED, 
configState.targetState(CONNECTOR_IDS.get(0)));
+assertEquals(SAMPLE_CONFIGS.get(0), 
configState.connectorConfig(CONNECTOR_IDS.get(0)));
+assertEquals(1, configState.connectors().size());
+
+
verify(configUpdateListener).onConnectorConfigUpdate(eq(CONNECTOR_IDS.get(0)));
+}
+
+@Test
+public void testPutConnectorConfigUpdateExisting() {
+configStore.putConnectorConfig(CONNECTOR_IDS.get(0), 
SAMPLE_CONFIGS.get(0));
+ClusterConfigState configState = configStore.snapshot();
+
+assertTrue(configState.contains(CONNECTOR_IDS.get(0)));
+// Default initial target state of STARTED should be used if no 
explicit target state is specified
+assertEquals(TargetState.STARTED, 
configState.targetState(CONNECTOR_IDS.get(0)));
+assertEquals(SAMPLE_CONFIGS.get(0), 
configState.connectorConfig(CONNECTOR_IDS.get(0)));
+assertEquals(1, configState.connectors().size());
+
+configStore.putConnectorConfig(CONNECTOR_IDS.get(0), 
SAMPLE_CONFIGS.get(1));
+configState = configStore.snapshot();
+assertEquals(SAMPLE_CONFIGS.get(1), 
configState.connectorConfig(CONNECTOR_IDS.get(0)));
+
+verify(configUpdateListener, 
times(2)).onConnectorConfigUpdate(eq(CONNECTOR_IDS.get(0)));
+}
+
+@Test
+public void testRemoveConnectorConfig() {
+configStore.putConnectorConfig(CONNECTOR_IDS.get(0), 
SAMPLE_CONFIGS.get(0));
+configStore.putConnectorConfig(CONNECTOR_IDS.get(1), 
SAMPLE_CONFIGS.get(1));
+ClusterConfigState configState = configStore.snapshot();
+
+assertTrue(configState.contains(CONNECTOR_IDS.get(0)));
+

Re: [PR] KAFKA-15570: Add unit tests for MemoryConfigBackingStore [kafka]

2023-10-10 Thread via GitHub


yashmayya commented on code in PR #14518:
URL: https://github.com/apache/kafka/pull/14518#discussion_r1354103192


##
connect/runtime/src/test/java/org/apache/kafka/connect/storage/MemoryConfigBackingStoreTest.java:
##
@@ -0,0 +1,183 @@
+/*
+ * 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.kafka.connect.storage;
+
+import org.apache.kafka.connect.runtime.TargetState;
+import org.apache.kafka.connect.util.ConnectorTaskId;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anySet;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class MemoryConfigBackingStoreTest {
+
+private static final List CONNECTOR_IDS = 
Arrays.asList("connector1", "connector2");
+
+// Actual values are irrelevant here and can be used as either connector 
or task configurations
+private static final List> SAMPLE_CONFIGS = 
Arrays.asList(
+Collections.singletonMap("config-key-one", "config-value-one"),
+Collections.singletonMap("config-key-two", "config-value-two"),
+Collections.singletonMap("config-key-three", "config-value-three")
+);
+
+@Mock
+private ConfigBackingStore.UpdateListener configUpdateListener;
+private final MemoryConfigBackingStore configStore = new 
MemoryConfigBackingStore();

Review Comment:
   JUnit creates a new instance of the test class for each test method run 
(exactly so that state isn't shared between tests), so this shouldn't really 
make a difference.



-- 
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: jira-unsubscr...@kafka.apache.org

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



Re: [PR] KAFKA-15570: Add unit tests for MemoryConfigBackingStore [kafka]

2023-10-10 Thread via GitHub


kpatelatwork commented on code in PR #14518:
URL: https://github.com/apache/kafka/pull/14518#discussion_r1353833312


##
connect/runtime/src/test/java/org/apache/kafka/connect/storage/MemoryConfigBackingStoreTest.java:
##
@@ -0,0 +1,183 @@
+/*
+ * 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.kafka.connect.storage;
+
+import org.apache.kafka.connect.runtime.TargetState;
+import org.apache.kafka.connect.util.ConnectorTaskId;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anySet;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class MemoryConfigBackingStoreTest {
+
+private static final List CONNECTOR_IDS = 
Arrays.asList("connector1", "connector2");
+
+// Actual values are irrelevant here and can be used as either connector 
or task configurations
+private static final List> SAMPLE_CONFIGS = 
Arrays.asList(
+Collections.singletonMap("config-key-one", "config-value-one"),
+Collections.singletonMap("config-key-two", "config-value-two"),
+Collections.singletonMap("config-key-three", "config-value-three")
+);
+
+@Mock
+private ConfigBackingStore.UpdateListener configUpdateListener;
+private final MemoryConfigBackingStore configStore = new 
MemoryConfigBackingStore();

Review Comment:
   should this be declared non-final and instantiated in the `setup()` instead 
so we don't share state between tests?



-- 
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: jira-unsubscr...@kafka.apache.org

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



Re: [PR] KAFKA-15570: Add unit tests for MemoryConfigBackingStore [kafka]

2023-10-10 Thread via GitHub


yashmayya commented on PR #14518:
URL: https://github.com/apache/kafka/pull/14518#issuecomment-1755155655

   @C0urante would you be able to take a look at this?


-- 
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: jira-unsubscr...@kafka.apache.org

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



[PR] KAFKA-15570: Add unit tests for MemoryConfigBackingStore [kafka]

2023-10-10 Thread via GitHub


yashmayya opened a new pull request, #14518:
URL: https://github.com/apache/kafka/pull/14518

   - https://issues.apache.org/jira/browse/KAFKA-15570
   - Currently, the 
[MemoryConfigBackingStore](https://github.com/apache/kafka/blob/6e164bb9ace3ea7a1a9542904d1a01c9fd3a1b48/connect/runtime/src/main/java/org/apache/kafka/connect/storage/MemoryConfigBackingStore.java#L37)
 class doesn't have any unit tests for its functionality.
   - While most of its functionality is fairly lightweight today, changes will 
be introduced with 
[KIP-980](https://cwiki.apache.org/confluence/display/KAFKA/KIP-980%3A+Allow+creating+connectors+in+a+stopped+state)
 (potentially 
[KIP-976](https://cwiki.apache.org/confluence/display/KAFKA/KIP-976%3A+Cluster-wide+dynamic+log+adjustment+for+Kafka+Connect)
 as well) and it would be good to have some basic tests in place before those 
changes are made.
   - This also makes it easier to introduce additional tests for newer 
functionality without having to add the irrelevant scaffolding then.
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


-- 
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: jira-unsubscr...@kafka.apache.org

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