|
| 1 | +package io.weaviate.integration; |
| 2 | + |
| 3 | +import org.assertj.core.api.Assertions; |
| 4 | +import org.junit.Test; |
| 5 | + |
| 6 | +import io.weaviate.ConcurrentTest; |
| 7 | +import io.weaviate.client6.v1.api.WeaviateClient; |
| 8 | +import io.weaviate.client6.v1.api.collections.tenants.Tenant; |
| 9 | +import io.weaviate.containers.Container; |
| 10 | +import io.weaviate.containers.Container.ContainerGroup; |
| 11 | +import io.weaviate.containers.MinIo; |
| 12 | +import io.weaviate.containers.Weaviate; |
| 13 | + |
| 14 | +public class TenantsITest extends ConcurrentTest { |
| 15 | + private static final ContainerGroup compose = Container.compose( |
| 16 | + Weaviate.custom() |
| 17 | + .withOffloadS3(MinIo.ACCESS_KEY, MinIo.SECRET_KEY) |
| 18 | + .build(), |
| 19 | + Container.MINIO); |
| 20 | + |
| 21 | + private static WeaviateClient client = compose.getClient(); |
| 22 | + |
| 23 | + @Test |
| 24 | + public void test_tenantLifecycle() throws Exception { |
| 25 | + var nsThings = ns("Things"); |
| 26 | + |
| 27 | + client.collections.create( |
| 28 | + nsThings, c -> c |
| 29 | + .multiTenancy(mt -> mt |
| 30 | + .autoTenantCreation(false) |
| 31 | + .autoTenantActivation(false))); |
| 32 | + |
| 33 | + var things = client.collections.use(nsThings); |
| 34 | + |
| 35 | + // No tenants at first |
| 36 | + Assertions.assertThat(things.tenants.list()).as("no tenants initially").isEmpty(); |
| 37 | + |
| 38 | + var allison = Tenant.active("active-allison"); |
| 39 | + var isaac = Tenant.inactive("inactive-isaac"); |
| 40 | + var owen = Tenant.inactive("offloaded-owen"); |
| 41 | + |
| 42 | + things.tenants.create(allison, isaac, owen); |
| 43 | + |
| 44 | + // Collection has 2 tenants creted just now. |
| 45 | + Assertions.assertThat(things.tenants.list()).as("list created tenants").hasSize(3); |
| 46 | + Assertions.assertThat(things.tenants.exists(allison.name())) |
| 47 | + .describedAs("%s exists", allison.name()).isTrue(); |
| 48 | + Assertions.assertThat(things.tenants.exists(isaac.name())) |
| 49 | + .describedAs("%s exists", isaac.name()).isTrue(); |
| 50 | + Assertions.assertThat(things.tenants.exists(owen.name())) |
| 51 | + .describedAs("%s exists", owen.name()).isTrue(); |
| 52 | + |
| 53 | + things.tenants.activate(isaac.name()); |
| 54 | + eventually(() -> things.tenants.get(isaac.name()).get().isActive(), |
| 55 | + 200, 2, isaac.name() + " not activated"); |
| 56 | + |
| 57 | + things.tenants.deactivate(allison.name()); |
| 58 | + eventually(() -> things.tenants.get(allison.name()).get().isInactive(), |
| 59 | + 200, 2, allison.name() + " not deactivated"); |
| 60 | + |
| 61 | + things.tenants.offload(owen.name()); |
| 62 | + eventually(() -> things.tenants.get(owen.name()).get().isOffloaded(), |
| 63 | + 200, 2, owen.name() + " not offloaded"); |
| 64 | + |
| 65 | + things.tenants.delete(allison.name(), isaac.name(), owen.name()); |
| 66 | + Assertions.assertThat(things.tenants.list()).as("no tenants after deletion").isEmpty(); |
| 67 | + Assertions.assertThat(things.tenants.exists(allison.name())) |
| 68 | + .describedAs("%s not exists", allison.name()).isFalse(); |
| 69 | + Assertions.assertThat(things.tenants.exists(isaac.name())) |
| 70 | + .describedAs("%s not exists", isaac.name()).isFalse(); |
| 71 | + Assertions.assertThat(things.tenants.exists(owen.name())) |
| 72 | + .describedAs("%s not exists", owen.name()).isFalse(); |
| 73 | + } |
| 74 | +} |
0 commit comments