|
7 | 7 |
|
8 | 8 | import io.weaviate.ConcurrentTest; |
9 | 9 | import io.weaviate.client6.v1.api.WeaviateClient; |
| 10 | +import io.weaviate.client6.v1.api.cluster.Node; |
| 11 | +import io.weaviate.client6.v1.api.cluster.NodeVerbosity; |
10 | 12 | import io.weaviate.client6.v1.api.cluster.ShardingState; |
| 13 | +import io.weaviate.client6.v1.api.cluster.replication.Replication; |
| 14 | +import io.weaviate.client6.v1.api.cluster.replication.ReplicationState; |
| 15 | +import io.weaviate.client6.v1.api.cluster.replication.ReplicationType; |
11 | 16 | import io.weaviate.containers.Weaviate; |
12 | 17 |
|
13 | 18 | public class ClusterITest extends ConcurrentTest { |
@@ -50,4 +55,80 @@ public void test_listNodes() throws IOException { |
50 | 55 | // Assert |
51 | 56 | Assertions.assertThat(allNodes).as("total no. nodes").hasSize(3); |
52 | 57 | } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void test_replicateLifecycle() throws IOException { |
| 61 | + // Arrange |
| 62 | + |
| 63 | + // We must create the collection first before any shards exist on the nodes. |
| 64 | + var nsThings = ns("Things"); |
| 65 | + client.collections.create(nsThings); |
| 66 | + |
| 67 | + var nodes = client.cluster.listNodes(opt -> opt.verbosity(NodeVerbosity.VERBOSE)); |
| 68 | + Assertions.assertThat(nodes) |
| 69 | + .as("cluster at least 2 nodes").hasSizeGreaterThanOrEqualTo(2); |
| 70 | + |
| 71 | + Node source = null; |
| 72 | + Node target = null; |
| 73 | + for (var node : nodes) { |
| 74 | + if (source == null && !node.shards().isEmpty()) { |
| 75 | + source = node; |
| 76 | + } else if (target == null) { |
| 77 | + target = node; |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + var wantShard = source.shards().get(0).name(); |
| 82 | + var srcNode = source.name(); |
| 83 | + var tgtNode = target.name(); |
| 84 | + |
| 85 | + // Act: start replication |
| 86 | + var replication = client.cluster.replicate( |
| 87 | + nsThings, |
| 88 | + wantShard, |
| 89 | + srcNode, |
| 90 | + tgtNode, |
| 91 | + ReplicationType.MOVE); |
| 92 | + |
| 93 | + var got = client.cluster.replication.get(replication.uuid()); |
| 94 | + Assertions.assertThat(got).get() |
| 95 | + .as("expected replication status") |
| 96 | + .returns(nsThings, Replication::collection) |
| 97 | + .returns(wantShard, Replication::shard) |
| 98 | + .returns(srcNode, Replication::sourceNode) |
| 99 | + .returns(tgtNode, Replication::targetNode) |
| 100 | + .returns(ReplicationType.MOVE, Replication::type) |
| 101 | + .returns(null, Replication::history) |
| 102 | + .extracting(Replication::status).isNotNull(); |
| 103 | + |
| 104 | + var withHistory = client.cluster.replication.get( |
| 105 | + replication.uuid(), |
| 106 | + repl -> repl.includeHistory(true)); |
| 107 | + Assertions.assertThat(withHistory).get() |
| 108 | + .as("includes history") |
| 109 | + .extracting(Replication::history).isNotNull(); |
| 110 | + |
| 111 | + // Act: query replications |
| 112 | + var filtered = client.cluster.replication.list( |
| 113 | + repl -> repl |
| 114 | + .collection(nsThings) |
| 115 | + .shard(wantShard) |
| 116 | + .targetNode(tgtNode)); |
| 117 | + |
| 118 | + Assertions.assertThat(filtered) |
| 119 | + .as("existing replications for %s-%s -> %s", nsThings, wantShard, tgtNode) |
| 120 | + .hasSize(1); |
| 121 | + |
| 122 | + // Act: cancel |
| 123 | + client.cluster.replication.cancel(replication.uuid()); |
| 124 | + |
| 125 | + eventually(() -> client.cluster.replication.get(replication.uuid()) |
| 126 | + .orElseThrow() |
| 127 | + .status().state() == ReplicationState.CANCELED, 1000, 25, "replication must be canceled"); |
| 128 | + |
| 129 | + // Act: delete replication |
| 130 | + client.cluster.replication.delete(replication.uuid()); |
| 131 | + |
| 132 | + eventually(() -> client.cluster.replication.list().isEmpty(), 1000, 15, "replication must be deleted"); |
| 133 | + } |
53 | 134 | } |
0 commit comments