-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #323 from weaviate/async_cluster
feature: async support for cluster package
- Loading branch information
Showing
9 changed files
with
533 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/io/weaviate/client/v1/async/cluster/Cluster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.weaviate.client.v1.async.cluster; | ||
|
||
import io.weaviate.client.Config; | ||
import io.weaviate.client.v1.async.cluster.api.NodesStatusGetter; | ||
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; | ||
|
||
public class Cluster { | ||
|
||
private final CloseableHttpAsyncClient client; | ||
private final Config config; | ||
|
||
public Cluster(CloseableHttpAsyncClient client, Config config) { | ||
this.client = client; | ||
this.config = config; | ||
} | ||
|
||
public NodesStatusGetter nodesStatusGetter() { | ||
return new NodesStatusGetter(client, config); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/io/weaviate/client/v1/async/cluster/api/NodesStatusGetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.weaviate.client.v1.async.cluster.api; | ||
|
||
import io.weaviate.client.Config; | ||
import io.weaviate.client.base.AsyncBaseClient; | ||
import io.weaviate.client.base.AsyncClientResult; | ||
import io.weaviate.client.base.Result; | ||
import io.weaviate.client.base.util.UrlEncoder; | ||
import io.weaviate.client.v1.cluster.model.NodesStatusResponse; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; | ||
import org.apache.hc.core5.concurrent.FutureCallback; | ||
|
||
import java.util.concurrent.Future; | ||
|
||
public class NodesStatusGetter extends AsyncBaseClient<NodesStatusResponse> | ||
implements AsyncClientResult<NodesStatusResponse> { | ||
|
||
private String className; | ||
private String output; | ||
|
||
public NodesStatusGetter(CloseableHttpAsyncClient client, Config config) { | ||
super(client, config); | ||
} | ||
|
||
public NodesStatusGetter withClassName(String className) { | ||
this.className = className; | ||
return this; | ||
} | ||
|
||
public NodesStatusGetter withOutput(String output) { | ||
this.output = output; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Future<Result<NodesStatusResponse>> run() { | ||
return run(null); | ||
} | ||
|
||
@Override | ||
public Future<Result<NodesStatusResponse>> run(FutureCallback<Result<NodesStatusResponse>> callback) { | ||
return sendGetRequest(path(), NodesStatusResponse.class, callback); | ||
} | ||
|
||
private String path() { | ||
String path = "/nodes"; | ||
if (StringUtils.isNotBlank(className)) { | ||
path = String.format("%s/%s", path, UrlEncoder.encodePathParam(className)); | ||
} | ||
if (StringUtils.isNotBlank(output)) { | ||
path = String.format("%s?%s", path, UrlEncoder.encodeQueryParam("output", output)); | ||
} | ||
return path; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...test/java/io/weaviate/integration/client/async/cluster/ClientClusterMultiTenancyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.weaviate.integration.client.async.cluster; | ||
|
||
import io.weaviate.client.Config; | ||
import io.weaviate.client.WeaviateClient; | ||
import io.weaviate.client.base.Result; | ||
import io.weaviate.client.v1.async.WeaviateAsyncClient; | ||
import io.weaviate.client.v1.async.cluster.api.NodesStatusGetter; | ||
import io.weaviate.client.v1.cluster.model.NodeStatusOutput; | ||
import io.weaviate.client.v1.cluster.model.NodesStatusResponse; | ||
import io.weaviate.integration.client.WeaviateDockerCompose; | ||
import io.weaviate.integration.client.WeaviateTestGenerics; | ||
import io.weaviate.integration.tests.cluster.ClusterMultiTenancyTestSuite; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
public class ClientClusterMultiTenancyTest { | ||
|
||
private WeaviateClient client; | ||
private final WeaviateTestGenerics testGenerics = new WeaviateTestGenerics(); | ||
|
||
@ClassRule | ||
public static WeaviateDockerCompose compose = new WeaviateDockerCompose(); | ||
|
||
@Before | ||
public void before() { | ||
Config config = new Config("http", compose.getHttpHostAddress()); | ||
client = new WeaviateClient(config); | ||
} | ||
|
||
@After | ||
public void after() { | ||
testGenerics.cleanupWeaviate(client); | ||
} | ||
|
||
|
||
@Test | ||
public void shouldGetNodeStatusPerClass() throws InterruptedException { | ||
Supplier<Result<NodesStatusResponse>> resultSupplierAll = createSupplier( | ||
nodesStatusGetter -> nodesStatusGetter | ||
.withOutput(NodeStatusOutput.VERBOSE) | ||
); | ||
Supplier<Result<NodesStatusResponse>> resultSupplierPizza = createSupplier( | ||
nodesStatusGetter -> nodesStatusGetter | ||
.withOutput(NodeStatusOutput.VERBOSE) | ||
.withClassName("Pizza") | ||
); | ||
Supplier<Result<NodesStatusResponse>> resultSupplierSoup = createSupplier( | ||
nodesStatusGetter -> nodesStatusGetter | ||
.withOutput(NodeStatusOutput.VERBOSE) | ||
.withClassName("Soup") | ||
); | ||
|
||
ClusterMultiTenancyTestSuite.testMultiTenancyDataPerClassOutputVerbose(resultSupplierAll, resultSupplierPizza, resultSupplierSoup, | ||
testGenerics, client); | ||
} | ||
|
||
private Supplier<Result<NodesStatusResponse>> createSupplier(Consumer<NodesStatusGetter> configure) { | ||
return () -> { | ||
try (WeaviateAsyncClient asyncClient = client.async()) { | ||
NodesStatusGetter nodesStatusGetter = asyncClient.cluster().nodesStatusGetter(); | ||
configure.accept(nodesStatusGetter); | ||
return nodesStatusGetter.run().get(); | ||
} catch (InterruptedException | ExecutionException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
src/test/java/io/weaviate/integration/client/async/cluster/ClientClusterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package io.weaviate.integration.client.async.cluster; | ||
|
||
import io.weaviate.client.Config; | ||
import io.weaviate.client.WeaviateClient; | ||
import io.weaviate.client.base.Result; | ||
import io.weaviate.client.v1.async.WeaviateAsyncClient; | ||
import io.weaviate.client.v1.async.cluster.api.NodesStatusGetter; | ||
import io.weaviate.client.v1.cluster.model.NodeStatusOutput; | ||
import io.weaviate.client.v1.cluster.model.NodesStatusResponse; | ||
import io.weaviate.integration.client.WeaviateDockerCompose; | ||
import io.weaviate.integration.client.WeaviateTestGenerics; | ||
import io.weaviate.integration.tests.cluster.ClusterTestSuite; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
public class ClientClusterTest { | ||
|
||
private WeaviateClient client; | ||
private final WeaviateTestGenerics testGenerics = new WeaviateTestGenerics(); | ||
|
||
@ClassRule | ||
public static WeaviateDockerCompose compose = new WeaviateDockerCompose(); | ||
|
||
@Before | ||
public void before() { | ||
Config config = new Config("http", compose.getHttpHostAddress()); | ||
client = new WeaviateClient(config); | ||
} | ||
|
||
@After | ||
public void after() { | ||
testGenerics.cleanupWeaviate(client); | ||
} | ||
|
||
@Test | ||
public void testClusterNodesEndpointWithoutDataWithOutputVerbose() { | ||
Supplier<Result<NodesStatusResponse>> resultSupplier = createSupplier( | ||
nodesStatusGetter -> nodesStatusGetter | ||
.withOutput(NodeStatusOutput.VERBOSE) | ||
); | ||
|
||
ClusterTestSuite.testNoDataOutputVerbose(resultSupplier); | ||
} | ||
|
||
@Test | ||
public void testClusterNodesEndpointWithDataWithOutputVerbose() throws InterruptedException { | ||
Supplier<Result<NodesStatusResponse>> resultSupplier = createSupplier( | ||
nodesStatusGetter -> nodesStatusGetter | ||
.withOutput(NodeStatusOutput.VERBOSE) | ||
); | ||
|
||
ClusterTestSuite.testDataOutputVerbose(resultSupplier, testGenerics, client); | ||
} | ||
|
||
@Test | ||
public void shouldGetNodeStatusPerClassWithOutputVerbose() throws InterruptedException { | ||
Supplier<Result<NodesStatusResponse>> resultSupplierAll = createSupplier( | ||
nodesStatusGetter -> nodesStatusGetter | ||
.withOutput(NodeStatusOutput.VERBOSE) | ||
); | ||
Supplier<Result<NodesStatusResponse>> resultSupplierPizza = createSupplier( | ||
nodesStatusGetter -> nodesStatusGetter | ||
.withOutput(NodeStatusOutput.VERBOSE) | ||
.withClassName("Pizza") | ||
); | ||
Supplier<Result<NodesStatusResponse>> resultSupplierSoup = createSupplier( | ||
nodesStatusGetter -> nodesStatusGetter | ||
.withOutput(NodeStatusOutput.VERBOSE) | ||
.withClassName("Soup") | ||
); | ||
|
||
ClusterTestSuite.testDataPerClassOutputVerbose(resultSupplierAll, resultSupplierPizza, resultSupplierSoup, | ||
testGenerics, client); | ||
} | ||
|
||
@Test | ||
public void testClusterNodesEndpointWithOutputMinimalImplicit() { | ||
Supplier<Result<NodesStatusResponse>> resultSupplier = createSupplier( | ||
nodesStatusGetter->{} | ||
); | ||
|
||
ClusterTestSuite.testNoDataOutputMinimalImplicit(resultSupplier); | ||
} | ||
|
||
private Supplier<Result<NodesStatusResponse>> createSupplier(Consumer<NodesStatusGetter> configure) { | ||
return () -> { | ||
try (WeaviateAsyncClient asyncClient = client.async()) { | ||
NodesStatusGetter nodesStatusGetter = asyncClient.cluster().nodesStatusGetter(); | ||
configure.accept(nodesStatusGetter); | ||
return nodesStatusGetter.run().get(); | ||
} catch (InterruptedException | ExecutionException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.