EgorBaranovEnjoysTyping commented on code in PR #13285: URL: https://github.com/apache/ignite/pull/13285#discussion_r3821164824
########## modules/ducktests/DEV_GUIDE.md: ########## @@ -0,0 +1,518 @@ +<!-- +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. +--> +# How to Write a New DuckTest + +The ignite-ducktests framework is a bilingual integration testing framework: + +| Layer | Language | Purpose | +|----------------------|----------|-------------------------------------------------------------------| +| Test orchestration | Python | Manages Docker containers, starts/stops nodes, asserts results | +| In-cluster workloads | Java | Runs inside Ignite nodes (cache ops, transactions, queries, etc.) | + +Each Ignite node runs in a separate Docker container. The Python layer manages container lifecycle and simulates network failures via iptables. + +--- +## Write a Java Application (if needed) + +All Java applications extend IgniteAwareApplication. Create a new file under: +modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/<your_package>/<YourApp>.java + +### Example: +```java +package org.apache.ignite.internal.ducktest.tests.mytest; + +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.ignite.internal.ducktest.utils.IgniteAwareApplication; + +public class MyTestApp extends IgniteAwareApplication { + @Override + protected void run(JsonNode params) throws Exception { + // 1. Signal initialization — Python side waits for this + markInitialized(); + // 2. Parse parameters passed from Python + String cacheName = params.get("cacheName").asText(); + int range = params.get("range").asInt(1000); + + // 3. Use the cluster (depends on service type) + // NODE mode → this.ignite (full Ignite node) + // THIN_CLIENT → this.client (IgniteClient) + // THIN_JDBC → this.thinJdbcDataSource + IgniteCache<Integer, String> cache = ignite.cache(cacheName); + for (int i = 0; i < range; i++) + cache.put(i, "val-" + i); + // 4. Record a result back to Python (readable via extract_result()) + recordResult("putCount", String.valueOf(range)); + + // 5. For long-running apps, loop until SIGTERM: + // while (!terminated()) { U.sleep(100); } + + // 6. Signal completion — Python side waits for this on stop() + markFinished(); + } +} +``` +--- +## Application Lifecycle Methods + +| Method | What it does | Python effect | +|-----------------------------|-------------------------------------|-------------------------------------------| +| markInitialized() | Prints IGNITE_APPLICATION_INITIALIZED | Required before start() returns | +| markFinished() | Prints IGNITE_APPLICATION_FINISHED | Required before stop() returns | +| markBroken(Throwable) | Prints IGNITE_APPLICATION_BROKEN | Raises IgniteExecutionException in Python | +| recordResult(name, value) | Prints name->value<- | Read via app.extract_result(name) | +| markSyncExecutionComplete() | Run-to-completion shortcut | Use instead of init + finish pair | + +--- +## Service Types (what connection the app gets) + +| Service Type | Python config class | Java field | +|------------------|-------------------------------|-------------------------| +| Full server node | IgniteConfiguration | this.ignite | +| Thin client | IgniteThinClientConfiguration | this.client | +| Thin JDBC | (same, mode=THIN_JDBC) | this.thinJdbcDataSource | Review Comment: Agree, done. ########## modules/ducktests/DEV_GUIDE.md: ########## @@ -0,0 +1,518 @@ +<!-- +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. +--> +# How to Write a New DuckTest + +The ignite-ducktests framework is a bilingual integration testing framework: + +| Layer | Language | Purpose | +|----------------------|----------|-------------------------------------------------------------------| +| Test orchestration | Python | Manages Docker containers, starts/stops nodes, asserts results | +| In-cluster workloads | Java | Runs inside Ignite nodes (cache ops, transactions, queries, etc.) | + +Each Ignite node runs in a separate Docker container. The Python layer manages container lifecycle and simulates network failures via iptables. + +--- +## Write a Java Application (if needed) + +All Java applications extend IgniteAwareApplication. Create a new file under: +modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/<your_package>/<YourApp>.java + +### Example: +```java +package org.apache.ignite.internal.ducktest.tests.mytest; + +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.ignite.internal.ducktest.utils.IgniteAwareApplication; + +public class MyTestApp extends IgniteAwareApplication { + @Override + protected void run(JsonNode params) throws Exception { + // 1. Signal initialization — Python side waits for this + markInitialized(); + // 2. Parse parameters passed from Python + String cacheName = params.get("cacheName").asText(); + int range = params.get("range").asInt(1000); + + // 3. Use the cluster (depends on service type) + // NODE mode → this.ignite (full Ignite node) + // THIN_CLIENT → this.client (IgniteClient) + // THIN_JDBC → this.thinJdbcDataSource + IgniteCache<Integer, String> cache = ignite.cache(cacheName); + for (int i = 0; i < range; i++) + cache.put(i, "val-" + i); + // 4. Record a result back to Python (readable via extract_result()) + recordResult("putCount", String.valueOf(range)); + + // 5. For long-running apps, loop until SIGTERM: + // while (!terminated()) { U.sleep(100); } + + // 6. Signal completion — Python side waits for this on stop() + markFinished(); + } +} +``` +--- +## Application Lifecycle Methods + +| Method | What it does | Python effect | +|-----------------------------|-------------------------------------|-------------------------------------------| +| markInitialized() | Prints IGNITE_APPLICATION_INITIALIZED | Required before start() returns | +| markFinished() | Prints IGNITE_APPLICATION_FINISHED | Required before stop() returns | +| markBroken(Throwable) | Prints IGNITE_APPLICATION_BROKEN | Raises IgniteExecutionException in Python | +| recordResult(name, value) | Prints name->value<- | Read via app.extract_result(name) | +| markSyncExecutionComplete() | Run-to-completion shortcut | Use instead of init + finish pair | + +--- +## Service Types (what connection the app gets) + +| Service Type | Python config class | Java field | +|------------------|-------------------------------|-------------------------| +| Full server node | IgniteConfiguration | this.ignite | +| Thin client | IgniteThinClientConfiguration | this.client | +| Thin JDBC | (same, mode=THIN_JDBC) | this.thinJdbcDataSource | +| No connection | service_type = NONE | nothing | + +--- +## Write a Python Test + +Create a new file under: +modules/ducktests/tests/ignitetest/tests/<your_test>.py +```python +from ignitetest.services.ignite import IgniteService +from ignitetest.services.ignite_app import IgniteApplicationService +from ignitetest.services.utils.ignite_configuration import ( + IgniteConfiguration, IgniteThinClientConfiguration, + ClientConnectorConfiguration +) +from ignitetest.services.utils.ignite_configuration.cache import CacheConfiguration +from ignitetest.utils import ignite_versions, cluster +from ignitetest.utils.ignite_test import IgniteTest +from ignitetest.utils.version import DEV_BRANCH, LATEST, IgniteVersion + +class MyTest(IgniteTest): + @cluster(num_nodes=3) # max containers needed + @ignite_versions(str(DEV_BRANCH), str(LATEST)) # parameterize by version + def test_cache_operations(self, ignite_version): + # ── 1. Start server nodes ────────────────────────────── + server_config = IgniteConfiguration( + version=IgniteVersion(ignite_version), + client_connector_configuration=ClientConnectorConfiguration(), + caches=[CacheConfiguration(name='test-cache', backups=1)] + ) + servers = IgniteService(self.test_context, server_config, num_nodes=2) + servers.start() + # ── 2. Start a client application ────────────────────── + addresses = [servers.nodes[0].account.hostname + ":" + + str(server_config.client_connector_configuration.port)] + client_config = IgniteThinClientConfiguration( + version=IgniteVersion(ignite_version), + addresses=addresses + ) + app = IgniteApplicationService( + self.test_context, + client_config, + java_class_name="org.apache.ignite.internal.ducktest.tests.mytest.MyTestApp", + params={"cacheName": "test-cache", "range": 1000} + ) + app.start() # blocks until IGNITE_APPLICATION_INITIALIZED + app.stop() # blocks until IGNITE_APPLICATION_FINISHED + # ── 3. Verify results ────────────────────────────────── + result = app.extract_result("putCount") + assert result == "1000", f"Expected 1000, got {result}" + servers.stop() +``` +--- +## Decorators Reference + +### @cluster Annotation +@cluster is a mandatory test method decorator. It tells the ducktape framework how many Docker containers the test will consume and how exactly. + +#### Basic Usage +```python +from ignitetest.utils import cluster +class MyTest(IgniteTest): + @cluster(num_nodes=3) + # Here num_nodes=3 means the test will consume up to 3 + # containers from the available pool (default 13, set via -n in + # run_tests.sh). + @ignite_versions(str(DEV_BRANCH), str(LATEST)) + def test_something(self, ignite_version): + servers = IgniteService(self.test_context, config, num_nodes=2) + servers.start() + # ... test logic ... + servers.stop() +``` +#### Key Points: + +1. The decorator wraps the test in before()/after() + This means self.test_context is guaranteed to be initialized before the test runs. + +2. num_nodes is the peak requirement + Specify the maximum number of containers the test may consume simultaneously. For example, if the test launches 2 + server nodes + 1 client app: +```python +@cluster(num_nodes=3) # 2 servers + 1 client = 3 +def test_with_client(self, ignite_version): + servers = IgniteService(self.test_context, config, num_nodes=2) + client = IgniteService(self.test_context, client_config, num_nodes=1) + servers.start() + client.start() +``` +3. Global cluster_size parameter. You can override num_nodes at runtime via a global parameter: + ./docker/run_tests.sh -g cluster_size=5 -t ./ignitetest/tests/my_test.py +4. Instead of num_nodes, you can specify a ClusterSpec from ducktape for typed node specifications: Review Comment: Agree, done. -- 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]
