EgorBaranovEnjoysTyping commented on code in PR #13285: URL: https://github.com/apache/ignite/pull/13285#discussion_r3585681700
########## modules/ducktests/DEV_GUIDE.md: ########## @@ -0,0 +1,541 @@ +<!-- +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 +) +from ignitetest.services.utils.ignite_configuration.cache import CacheConfiguration +from ignitetest.services.utils.ignite_configuration.discovery import from_ignite_cluster +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), + caches=[CacheConfiguration(name='test-cache', backups=1)] + ) + servers = IgniteService(self.test_context, server_config, num_nodes=2) + servers.start() + # ── 2. Start a client application ────────────────────── + client_config = IgniteThinClientConfiguration( + version=IgniteVersion(ignite_version), + discovery_spi=from_ignite_cluster(servers) Review Comment: Done ########## modules/ducktests/DEV_GUIDE.md: ########## @@ -0,0 +1,541 @@ +<!-- +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 +) +from ignitetest.services.utils.ignite_configuration.cache import CacheConfiguration +from ignitetest.services.utils.ignite_configuration.discovery import from_ignite_cluster +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), + caches=[CacheConfiguration(name='test-cache', backups=1)] + ) + servers = IgniteService(self.test_context, server_config, num_nodes=2) + servers.start() + # ── 2. Start a client application ────────────────────── + client_config = IgniteThinClientConfiguration( + version=IgniteVersion(ignite_version), + discovery_spi=from_ignite_cluster(servers) + ) + 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 + # ── 3. Verify results ────────────────────────────────── + result = app.extract_result("putCount") Review Comment: 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]
