Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

5 changes: 3 additions & 2 deletions src/it/java/io/weaviate/containers/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public static class Group implements Startable {
private Group(Weaviate weaviate, GenericContainer<?>... containers) {
this.weaviate = weaviate;
this.containers = Arrays.asList(containers);

weaviate.dependsOn(containers);
setSharedNetwork();
}

Expand All @@ -63,8 +65,7 @@ public WeaviateClient getClient() {

@Override
public void start() {
containers.forEach(GenericContainer::start);
weaviate.start();
weaviate.start(); // testcontainers will resolve dependencies
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/it/java/io/weaviate/containers/Contextionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Contextionary build() {
.withEnv("EXTENSIONS_STORAGE_ORIGIN", "http://weaviate:8080")
.withEnv("NEIGHBOR_OCCURRENCE_IGNORE_PERCENTILE", "5")
.withEnv("ENABLE_COMPOUND_SPLITTING", "'false'");
container.withCreateContainerCmdModifier(cmd -> cmd.withHostName("contextionary"));
container.withCreateContainerCmdModifier(cmd -> cmd.withHostName(HOST_NAME));
return container;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/it/java/io/weaviate/containers/Weaviate.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ public Builder withDefaultVectorizer(String module) {
return this;
}

public Builder withContextionary() {
addModule(Contextionary.MODULE);
return this;
}

public Builder withContextionaryUrl(String url) {
withContextionary();
contextionaryUrl = url;
return this;
}
Expand Down
6 changes: 3 additions & 3 deletions src/it/java/io/weaviate/integration/AggregationITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import io.weaviate.client6.v1.collections.Property;
import io.weaviate.client6.v1.collections.VectorIndex;
import io.weaviate.client6.v1.collections.Vectorizer;
import io.weaviate.client6.v1.collections.Vectors;
import io.weaviate.client6.v1.collections.aggregate.AggregateGroupByRequest.GroupBy;
import io.weaviate.client6.v1.collections.aggregate.AggregateGroupByResponse;
import io.weaviate.client6.v1.collections.aggregate.Group;
import io.weaviate.client6.v1.collections.aggregate.GroupedBy;
import io.weaviate.client6.v1.collections.aggregate.IntegerMetric;
import io.weaviate.client6.v1.collections.aggregate.Metric;
import io.weaviate.client6.v1.collections.object.Vectors;
import io.weaviate.containers.Container;

public class AggregationITest extends ConcurrentTest {
Expand All @@ -36,7 +36,7 @@ public static void beforeAll() throws IOException {
.properties(
Property.text("category"),
Property.integer("price"))
.vectors(Vectors.of(new VectorIndex<>(Vectorizer.none()))));
.vectors(io.weaviate.client6.v1.collections.Vectors.of(new VectorIndex<>(Vectorizer.none()))));

var things = client.collections.use(COLLECTION);
for (var category : List.of("Shoes", "Hat", "Jacket")) {
Expand All @@ -47,7 +47,7 @@ public static void beforeAll() throws IOException {
things.data.insert(Map.of(
"category", category,
"price", category.length()),
meta -> meta.vectors(vector));
meta -> meta.vectors(Vectors.of(vector)));
}
}
}
Expand Down
91 changes: 91 additions & 0 deletions src/it/java/io/weaviate/integration/CollectionsITest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package io.weaviate.integration;

import java.io.IOException;

import org.assertj.core.api.Assertions;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.Test;

import io.weaviate.ConcurrentTest;
import io.weaviate.client6.WeaviateClient;
import io.weaviate.client6.v1.collections.Collection;
import io.weaviate.client6.v1.collections.Property;
import io.weaviate.client6.v1.collections.VectorIndex;
import io.weaviate.client6.v1.collections.VectorIndex.IndexType;
import io.weaviate.client6.v1.collections.VectorIndex.IndexingStrategy;
import io.weaviate.client6.v1.collections.Vectorizer;
import io.weaviate.client6.v1.collections.Vectors;
import io.weaviate.containers.Container;
import io.weaviate.containers.Contextionary;

public class CollectionsITest extends ConcurrentTest {
private static WeaviateClient client = Container.WEAVIATE.getClient();

@Test
public void testCreateGetDelete() throws IOException {
var collectionName = ns("Things");
client.collections.create(collectionName,
col -> col
.properties(Property.text("username"), Property.integer("age"))
.vector(new VectorIndex<>(IndexingStrategy.hnsw(), Vectorizer.none())));

var thingsCollection = client.collections.getConfig(collectionName);

Assertions.assertThat(thingsCollection).get()
.hasFieldOrPropertyWithValue("name", collectionName)
.extracting(Collection::vectors).extracting(Vectors::getDefault)
.as("default vector").satisfies(defaultVector -> {
Assertions.assertThat(defaultVector).extracting(VectorIndex::vectorizer)
.as("has none vectorizer").isInstanceOf(Contextionary.class);
Assertions.assertThat(defaultVector).extracting(VectorIndex::configuration)
.as("has hnsw index").returns(IndexType.HNSW, IndexingStrategy::type);
});

client.collections.delete(collectionName);
var noCollection = client.collections.getConfig(collectionName);
Assertions.assertThat(noCollection).as("after delete").isEmpty();
}

@Test
public void testCrossReferences() throws IOException {
// Arrange: Create Owners collection
var nsOwners = ns("Owners");
client.collections.create(nsOwners);

// Act: Create Things collection with owner -> owners
var nsThings = ns("Things");
client.collections.create(nsThings,
col -> col.properties(Property.reference("ownedBy", nsOwners)));
var things = client.collections.use(nsThings);

// Assert: Things --ownedBy-> Owners
Assertions.assertThat(things.config.get())
.as("after create Things").get()
.satisfies(c -> {
Assertions.assertThat(c.properties())
.as("ownedBy").filteredOn(p -> p.name().equals("ownedBy")).first()
.extracting(p -> p.dataTypes()).asInstanceOf(InstanceOfAssertFactories.LIST)
.containsOnly(nsOwners);
});

// Arrange: Create OnlineStores and Markets collections
var nsOnlineStores = ns("OnlineStores");
client.collections.create(nsOnlineStores);

var nsMarkets = ns("Markets");
client.collections.create(nsMarkets);

// Act: Update Things collections to add polymorphic reference
things.config.addProperty(Property.reference("soldIn", nsOnlineStores, nsMarkets));

// Assert: Things --soldIn-> [OnlineStores, Markets]
Assertions.assertThat(things.config.get())
.as("after add property").get()
.satisfies(c -> {
Assertions.assertThat(c.properties())
.as("soldIn").filteredOn(p -> p.name().equals("soldIn")).first()
.extracting(p -> p.dataTypes()).asInstanceOf(InstanceOfAssertFactories.LIST)
.containsOnly(nsOnlineStores, nsMarkets);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.weaviate.client6.v1;
package io.weaviate.integration;

import java.io.IOException;
import java.util.Map;
Expand All @@ -14,30 +14,34 @@
import io.weaviate.client6.v1.collections.VectorIndex;
import io.weaviate.client6.v1.collections.VectorIndex.IndexingStrategy;
import io.weaviate.client6.v1.collections.Vectorizer;
import io.weaviate.client6.v1.collections.object.Vectors;
import io.weaviate.containers.Container;

public class DataITest extends ConcurrentTest {

private static WeaviateClient client = Container.WEAVIATE.getClient();
private static final String COLLECTION = unique("Things");
private static final String COLLECTION = unique("Artists");
private static final String VECTOR_INDEX = "bring_your_own";

@BeforeClass
public static void beforeAll() throws IOException {
createTestCollection();
createTestCollections();
}

@Test
public void testCreateGetDelete() throws IOException {
var things = client.collections.use(COLLECTION);
var artists = client.collections.use(COLLECTION);
var id = randomUUID();
Float[] vector = { 1f, 2f, 3f };

things.data.insert(Map.of("username", "john doe"), metadata -> metadata
artists.data.insert(Map.of("name", "john doe"), metadata -> metadata
.id(id)
.vectors(Vectors.of(VECTOR_INDEX, vector)));

var object = things.data.get(id, query -> query.withVector());
var object = artists.data.get(id, query -> query
.returnProperties("name")
.includeVector());

Assertions.assertThat(object)
.as("object exists after insert").get()
.satisfies(obj -> {
Expand All @@ -50,18 +54,27 @@ public void testCreateGetDelete() throws IOException {

Assertions.assertThat(obj.properties())
.as("has expected properties")
.containsEntry("username", "john doe");
.containsEntry("name", "john doe");
});

things.data.delete(id);
object = things.data.get(id);
artists.data.delete(id);
object = artists.data.get(id);
Assertions.assertThat(object).isEmpty().as("object not exists after deletion");
}

private static void createTestCollection() throws IOException {
private static void createTestCollections() throws IOException {
var awardsGrammy = unique("Grammy");
client.collections.create(awardsGrammy);

var awardsOscar = unique("Oscar");
client.collections.create(awardsOscar);

client.collections.create(COLLECTION,
col -> col
.properties(Property.text("username"), Property.integer("age"))
.properties(
Property.text("name"),
Property.integer("age"),
Property.reference("hasAwards", awardsGrammy, awardsOscar))
.vector(VECTOR_INDEX, new VectorIndex<>(IndexingStrategy.hnsw(), Vectorizer.none())));
}
}
Loading