### Run Tests with Gradle Source: https://github.com/etcd-io/jetcd/blob/main/README.md Execute the project's test suite using Gradle. This command will start an etcd setup using the integrated launcher and run all defined tests. ```bash $ ./gradlew test ``` -------------------------------- ### Perform KV Operations (Put, Get, Delete) Source: https://github.com/etcd-io/jetcd/blob/main/README.md Example demonstrating basic Key-Value operations: putting a key-value pair, retrieving it, and then deleting it. This requires obtaining the KV client from the main client instance. ```java KV kvClient = client.getKVClient(); ByteSequence key = ByteSequence.from("test_key".getBytes()); ByteSequence value = ByteSequence.from("test_value".getBytes()); // put the key-value kvClient.put(key, value).get(); // get the CompletableFuture CompletableFuture getFuture = kvClient.get(key); // get the value from CompletableFuture GetResponse response = getFuture.get(); // delete the key kvClient.delete(key).get(); ``` -------------------------------- ### Start Isolated etcd Cluster for Testing Source: https://github.com/etcd-io/jetcd/blob/main/README.md Utilize the `EtcdClusterExtension` from `jetcd-test` to programmatically start and stop an isolated etcd server for integration testing. This requires JUnit 5 and Testcontainers. ```java import io.etcd.jetcd.Client; import io.etcd.jetcd.test.EtcdClusterExtension; import org.junit.jupiter.api.extension.RegisterExtension; @RegisterExtension public static final EtcdClusterExtension cluster = EtcdClusterExtension.builder() .withNodes(1) .build(); Client client = Client.builder().endpoints(cluster.clientEndpoints()).build(); ``` -------------------------------- ### Retrieve All Keys with Sorting and Range Source: https://github.com/etcd-io/jetcd/blob/main/docs/KeyVal.adoc Demonstrates how to retrieve all keys in descending order, starting from a specific key. This is useful for paginating or fetching a subset of keys based on a range. ```java ByteSequence key = ByteSequence.fromString("\0"); GetOption option = GetOption.newBuilder() .withSortField(GetOption.SortTarget.KEY) .withSortOrder(GetOption.SortOrder.DESCEND) .withRange(key) .build(); CompletableFuture futureResponse = client.getKVClient().get(key, option); GetResponse response = futureResponse.get(); Map keyValueMap = new HashMap<>(); for (KeyValue kv : response.getKvs()) { keyValueMap.put( kv.getKey().toStringUtf8(), kv.getValue().toStringUtf8() ); } ``` -------------------------------- ### Watch Key Changes using jetcd-ctl Source: https://github.com/etcd-io/jetcd/blob/main/jetcd-ctl/README.md Monitor a specific key for changes (PUT, DELETE events) starting from a given revision. This allows real-time observation of key modifications. ```bash $ gradle run --args="watch foo --rev=2" 21:35:09.162|INFO |CommandWatch - type=PUT, key=foo, value=bar 21:35:09.164|INFO |CommandWatch - type=PUT, key=foo, value=bar2 ``` -------------------------------- ### Get Key Value using jetcd-ctl Source: https://github.com/etcd-io/jetcd/blob/main/jetcd-ctl/README.md Retrieve the value associated with a specific key from the etcd cluster. This command shows the current value of the key. ```bash $ gradle run --args="get foo" 21:41:00.265|INFO |CommandGet - foo 21:41:00.267|INFO |CommandGet - bar2 ``` -------------------------------- ### Get Key Value at Specific Revision using jetcd-ctl Source: https://github.com/etcd-io/jetcd/blob/main/jetcd-ctl/README.md Retrieve the value of a key as it existed at a particular etcd revision. This is useful for historical data retrieval. ```bash $ gradle run --args="get foo --rev=2" 21:42:03.371|INFO |CommandGet - foo 21:42:03.373|INFO |CommandGet - bar ``` -------------------------------- ### Apply License Headers with Gradle Source: https://github.com/etcd-io/jetcd/blob/main/CONTRIBUTING.md Run this command to format license headers according to project standards. Ensure this is done before opening a Pull Request. ```bash ./gradlew spotlessApply ``` -------------------------------- ### Compile Java Code with Gradle Source: https://github.com/etcd-io/jetcd/blob/main/README.md Build the project by compiling the Java source files using Gradle. This is a prerequisite for running tests. ```bash ./gradlew compileJava ``` -------------------------------- ### Create etcd Client using Endpoints Source: https://github.com/etcd-io/jetcd/blob/main/README.md Instantiate an etcd client by providing a list of etcd server endpoints. Ensure the endpoints are correctly formatted. ```java // create client using endpoints Client client = Client.builder().endpoints("http://etcd0:2379", "http://etcd1:2379", "http://etcd2:2379").build(); ``` -------------------------------- ### Release Process for jetcd Source: https://github.com/etcd-io/jetcd/blob/main/docs/RELEASE.adoc This sequence of commands outlines the steps to release a new version of the jetcd project using Gradle. It includes checking the current version, performing the release, tagging the commit, and publishing the artifact. ```shell $ ./gradlew currentVersion Project version: 0.7.5-SNAPSHOT $ ./gradlew release $ git tag jetcd-0.7.5 $ ./gradlew currentVersion Project version: 0.7.5 $ ./gradlew publish published jetcd-0.7.5 release version $ ./gradlew markNextVersion -Prelease.version=0.7.6 ``` -------------------------------- ### Create etcd Client using Target Source: https://github.com/etcd-io/jetcd/blob/main/README.md Build an etcd client using a target string, which allows gRPC-java's name resolution mechanisms (e.g., DNS). ```java // create client using target which enable using any name resolution mechanism provided // by grpc-java (i.e. dns:///foo.bar.com:2379) Client client = Client.builder().target("ip:///etcd0:2379,etcd1:2379,etcd2:2379").build(); ``` -------------------------------- ### Put Key-Value Pair using jetcd-ctl Source: https://github.com/etcd-io/jetcd/blob/main/jetcd-ctl/README.md Use this command to insert or update a key-value pair in the etcd cluster. Ensure an etcd node is running and accessible. ```bash $ gradle run --args="put foo bar" 21:39:06.126|INFO |CommandPut - OK ``` ```bash $ gradle run --args="put foo bar2" 21:39:06.126|INFO |CommandPut - OK ``` -------------------------------- ### Build Jectd Client with TLS Configuration Source: https://github.com/etcd-io/jetcd/blob/main/docs/SslConfig.md Use this snippet to build a Jectd client that connects to an Etcd cluster secured with TLS. Ensure your certificate files (ca.crt, client.crt, client.key.pem) are correctly placed and formatted. The client is configured with the SSL context and then used to list cluster members. ```java File cert = new File("ca.crt"); File keyCertChainFile = new File("etcdctl-etcd-client.crt"); File keyFile = new File("etcdctl-etcd-client.key.pem"); SslContext context = GrpcSslContexts.forClient() .trustManager(cert) .keyManager(keyCertChainFile, keyFile) .build(); Client client = Client.builder() .endpoints("https://10.168.168.66:2379") .sslContext(context) .build(); client.getClusterClient().listMember().get().getMembers().forEach(member -> { logger.info("member: {}", member); }); ``` -------------------------------- ### Commit Message Format Source: https://github.com/etcd-io/jetcd/blob/main/CONTRIBUTING.md Follow this convention for commit messages to clearly indicate what changed and why. The subject line should be concise, followed by a blank line, and then a more detailed explanation. ```git scripts: add the test-cluster command this uses tmux to setup a test cluster that can easily be killed and started for debugging. Fixes #38 ``` ```git :