Skip to content

Commit

Permalink
[#754] Drop extra databases for testing multitenancy
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD authored and gavinking committed May 18, 2021
1 parent 6022533 commit 4c61672
Showing 1 changed file with 21 additions and 0 deletions.
Expand Up @@ -5,6 +5,7 @@
*/
package org.hibernate.reactive;

import java.util.Arrays;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.Id;
Expand All @@ -17,12 +18,15 @@
import org.hibernate.reactive.provider.Settings;
import org.hibernate.reactive.stage.Stage;
import org.hibernate.reactive.testing.DatabaseSelectionRule;
import org.hibernate.reactive.util.impl.CompletionStages;

import org.junit.AfterClass;
import org.junit.Rule;
import org.junit.Test;

import io.vertx.ext.unit.TestContext;

import static org.hibernate.reactive.MyCurrentTenantIdentifierResolver.Tenant.values;
import static org.hibernate.reactive.MyCurrentTenantIdentifierResolver.Tenant.DEFAULT;
import static org.hibernate.reactive.MyCurrentTenantIdentifierResolver.Tenant.TENANT_1;
import static org.hibernate.reactive.MyCurrentTenantIdentifierResolver.Tenant.TENANT_2;
Expand Down Expand Up @@ -96,6 +100,23 @@ public void testTenantSelection(TestContext context) {
);
}

@AfterClass
public static void dropDatabases(TestContext context) {
test( context, getSessionFactory()
.withSession( session -> Arrays
.stream( values() )
.filter( tenant -> tenant != DEFAULT )
.collect(
CompletionStages::voidFuture,
(stage, tenant) -> session
.createNativeQuery( "drop database if exists " + tenant.getDbName() + ";" )
.executeUpdate()
.thenCompose( CompletionStages::voidFuture ),
(stage, stage2) -> stage.thenCompose( v -> stage2 )
)
) );
}

private void assertThatPigsAreEqual(TestContext context, GuineaPig expected, GuineaPig actual) {
context.assertNotNull( actual );
context.assertEquals( expected.getId(), actual.getId() );
Expand Down

0 comments on commit 4c61672

Please sign in to comment.