Skip to content

Commit

Permalink
Add support for asyncEnabled replication seetting
Browse files Browse the repository at this point in the history
  • Loading branch information
antas-marcin committed Jul 17, 2024
1 parent 340f6a4 commit 60f913a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
@EqualsAndHashCode
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
public class ReplicationConfig {
Boolean asyncEnabled;
Integer factor;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,63 +45,17 @@ public void after() {

@Test
public void shouldCreateClassWithImplicitReplicationFactor() {
// given
int replicationFactor = 1;

String className = "Band";
WeaviateClass clazz = WeaviateClass.builder()
.className(className)
.description("Band that plays and produces music")
.vectorIndexType("hnsw")
.vectorizer("text2vec-contextionary")
.build();

// when
Result<Boolean> createStatus = client1.schema().classCreator().withClass(clazz).run();
assertThat(createStatus).isNotNull()
.returns(false, Result::hasErrors)
.returns(true, Result::getResult);

// then
Result<WeaviateClass> classResult = client1.schema().classGetter().withClassName(className).run();
assertThat(classResult).isNotNull()
.returns(false, Result::hasErrors)
.extracting(Result::getResult).isNotNull()
.extracting(WeaviateClass::getReplicationConfig)
.isNotNull()
.extracting(ReplicationConfig::getFactor)
.isEqualTo(replicationFactor);
validateClassReplicationSettings(1, false);
}

@Test
public void shouldCreateClassWithExplicitReplicationFactor() {
// given
int replicationFactor = 2;

String className = "Band";
WeaviateClass clazz = WeaviateClass.builder()
.className(className)
.description("Band that plays and produces music")
.vectorIndexType("hnsw")
.vectorizer("text2vec-contextionary")
.replicationConfig(ReplicationConfig.builder().factor(replicationFactor).build())
.build();

// when
Result<Boolean> createStatus = client1.schema().classCreator().withClass(clazz).run();
assertThat(createStatus).isNotNull()
.returns(false, Result::hasErrors)
.returns(true, Result::getResult);
validateClassReplicationSettings(2, false);
}

// then
Result<WeaviateClass> classResult = client1.schema().classGetter().withClassName(className).run();
assertThat(classResult).isNotNull()
.returns(false, Result::hasErrors)
.extracting(Result::getResult).isNotNull()
.extracting(WeaviateClass::getReplicationConfig)
.isNotNull()
.extracting(ReplicationConfig::getFactor)
.isEqualTo(replicationFactor);
@Test
public void shouldCreateClassWithAsyncReplicationAndExplicitReplicationFactor() {
validateClassReplicationSettings(2, true);
}

@Test
Expand Down Expand Up @@ -494,4 +448,40 @@ public void shouldBatchObjectsWithNestedProperties_NoSchema2() {
schemaClass = utils.getClass(client2, className);
utils.assertThatSchemaPropertiesHaveDataTypes(expectedProps, schemaClass);
}

private void validateClassReplicationSettings(int replicationFactor, boolean asyncEnabled) {
// given
ReplicationConfig.ReplicationConfigBuilder replicationConfigBuilder = ReplicationConfig.builder().factor(replicationFactor);
if (asyncEnabled) {
replicationConfigBuilder = replicationConfigBuilder.asyncEnabled(true);
}
String className = "Band";
WeaviateClass clazz = WeaviateClass.builder()
.className(className)
.description("Band that plays and produces music")
.vectorIndexType("hnsw")
.vectorizer("text2vec-contextionary")
.replicationConfig(replicationConfigBuilder.build())
.build();

// when
Result<Boolean> createStatus = client1.schema().classCreator().withClass(clazz).run();
assertThat(createStatus).isNotNull()
.returns(false, Result::hasErrors)
.returns(true, Result::getResult);

// then
Result<WeaviateClass> classResult = client1.schema().classGetter().withClassName(className).run();
assertThat(classResult).isNotNull()
.returns(false, Result::hasErrors)
.extracting(Result::getResult).isNotNull()
.extracting(WeaviateClass::getReplicationConfig)
.isNotNull()
.satisfies(rc -> {
assertThat(rc.getFactor()).isEqualTo(replicationFactor);
if (asyncEnabled) {
assertThat(rc.getAsyncEnabled()).isEqualTo(true);
}
});
}
}

0 comments on commit 60f913a

Please sign in to comment.