Skip to content

Commit 1e2bbd2

Browse files
committed
[#1582] Clean up, refactoring, fixes
1 parent b7c108b commit 1e2bbd2

File tree

75 files changed

+1259
-1957
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1259
-1957
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/adaptor/impl/ResultSetAdaptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import io.vertx.sqlclient.desc.ColumnDescriptor;
4343

4444
/**
45-
* An adaptor that allows Hibenate core code which expects a JDBC
45+
* An adaptor that allows Hibernate core code which expects a JDBC
4646
* {@code ResultSet} to read values from Vert.x's {@code RowSet}.
4747
*/
4848
public class ResultSetAdaptor implements ResultSet {

hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/exec/internal/StandardReactiveSelectExecutor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ public <T, R> CompletionStage<T> executeQuery(
116116
}
117117

118118
return doExecuteQuery( jdbcSelect, jdbcParameterBindings, executionContext, rowTransformer, domainResultType, statementCreator, resultsConsumer )
119-
.thenCompose( list ->
119+
.thenCompose( list -> ( (ReactivePersistenceContextAdapter) persistenceContext )
120120
// only initialize non-lazy collections after everything else has been refreshed
121-
((ReactivePersistenceContextAdapter) persistenceContext ).reactiveInitializeNonLazyCollections()
122-
.thenApply(v -> list)
121+
.reactiveInitializeNonLazyCollections()
122+
.thenApply( v -> list )
123123
)
124124
.whenComplete( (o, throwable) -> {
125125
if ( readOnly != null ) {

hibernate-reactive-core/src/test/java/org/hibernate/reactive/BaseReactiveTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
*/
6666
@ExtendWith(VertxExtension.class)
6767
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
68-
@Timeout(value = 600, timeUnit = TimeUnit.SECONDS)
68+
@Timeout(value = 20, timeUnit = TimeUnit.MINUTES)
6969
public abstract class BaseReactiveTest {
7070
/**
7171
* Configure Vertx JUnit5 test context
@@ -75,7 +75,7 @@ public abstract class BaseReactiveTest {
7575

7676
private static VertxOptions vertxOptions() {
7777
return new VertxOptions()
78-
.setBlockedThreadCheckInterval( 5 )
78+
.setBlockedThreadCheckInterval( 10 )
7979
.setBlockedThreadCheckIntervalUnit( TimeUnit.MINUTES );
8080
}
8181

@@ -194,7 +194,6 @@ protected CompletionStage<Void> setupSessionFactory(Configuration configuration)
194194
* Set up the session factory but create the configuration only if necessary.
195195
*
196196
* @param confSupplier supplies the configuration for the factory
197-
*
198197
* @return a {@link CompletionStage} void that succeeds when the factory is ready.
199198
*/
200199
protected CompletionStage<Void> setupSessionFactory(Supplier<Configuration> confSupplier) {

hibernate-reactive-core/src/test/java/org/hibernate/reactive/BatchFetchTest.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@
99
import java.util.Collection;
1010
import java.util.List;
1111
import java.util.Objects;
12-
import java.util.concurrent.CompletionStage;
13-
import java.util.concurrent.TimeUnit;
1412

1513
import org.hibernate.Hibernate;
1614
import org.hibernate.LockMode;
1715
import org.hibernate.annotations.BatchSize;
18-
import org.hibernate.reactive.util.impl.CompletionStages;
1916

17+
import org.junit.jupiter.api.AfterEach;
2018
import org.junit.jupiter.api.Disabled;
2119
import org.junit.jupiter.api.Test;
2220

23-
import io.vertx.junit5.Timeout;
2421
import io.vertx.junit5.VertxTestContext;
2522
import jakarta.persistence.CascadeType;
2623
import jakarta.persistence.Entity;
@@ -44,18 +41,18 @@
4441
import static org.junit.jupiter.api.Assertions.assertFalse;
4542
import static org.junit.jupiter.api.Assertions.assertTrue;
4643

47-
@Timeout( value = 5, timeUnit = TimeUnit.MINUTES ) // DB2 seems to take longer than other DB's
4844
public class BatchFetchTest extends BaseReactiveTest {
4945

5046
@Override
5147
protected Collection<Class<?>> annotatedEntities() {
5248
return List.of( Element.class, Node.class );
5349
}
5450

55-
@Override
56-
public CompletionStage<Void> cleanDb() {
57-
getSessionFactory().close();
58-
return CompletionStages.voidFuture();
51+
@AfterEach
52+
public void cleanDb(VertxTestContext context) {
53+
test( context, getSessionFactory()
54+
.withTransaction( s -> s.createQuery( "delete from Element" ).executeUpdate()
55+
.thenCompose( v -> s.createQuery( "delete from Node" ).executeUpdate() ) ) );
5956
}
6057

6158
@Test

hibernate-reactive-core/src/test/java/org/hibernate/reactive/BatchQueryOnConnectionTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.util.List;
1212
import java.util.Set;
1313
import java.util.concurrent.CompletionStage;
14-
import java.util.concurrent.TimeUnit;
1514

1615
import org.hibernate.reactive.pool.ReactiveConnection;
1716
import org.hibernate.reactive.pool.impl.OracleParameters;
@@ -20,15 +19,13 @@
2019

2120
import org.junit.jupiter.api.Test;
2221

23-
import io.vertx.junit5.Timeout;
2422
import io.vertx.junit5.VertxTestContext;
2523
import jakarta.persistence.Entity;
2624
import jakarta.persistence.Id;
2725

2826
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;
2927
import static org.junit.jupiter.api.Assertions.assertEquals;
3028

31-
@Timeout( value = 5, timeUnit = TimeUnit.MINUTES )
3229
public class BatchQueryOnConnectionTest extends BaseReactiveTest {
3330

3431
private static final int BATCH_SIZE = 20;

hibernate-reactive-core/src/test/java/org/hibernate/reactive/BatchingConnectionTest.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
package org.hibernate.reactive;
77

8-
import java.util.concurrent.CompletionStage;
9-
import java.util.concurrent.TimeUnit;
108

119
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
1210
import org.hibernate.cfg.AvailableSettings;
@@ -18,19 +16,17 @@
1816
import org.hibernate.reactive.stage.impl.StageSessionImpl;
1917
import org.hibernate.reactive.stage.impl.StageStatelessSessionImpl;
2018
import org.hibernate.reactive.testing.SqlStatementTracker;
21-
import org.hibernate.reactive.util.impl.CompletionStages;
2219

20+
import org.junit.jupiter.api.BeforeEach;
2321
import org.junit.jupiter.api.Test;
2422

25-
import io.vertx.junit5.Timeout;
2623
import io.vertx.junit5.VertxTestContext;
2724

2825
import static org.assertj.core.api.Assertions.assertThat;
2926
import static org.hibernate.reactive.util.impl.CompletionStages.loop;
3027
import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture;
3128
import static org.junit.jupiter.api.Assertions.assertEquals;
3229

33-
@Timeout( value = 5, timeUnit = TimeUnit.MINUTES )
3430
public class BatchingConnectionTest extends ReactiveSessionTest {
3531

3632
private static SqlStatementTracker sqlTracker;
@@ -46,6 +42,11 @@ protected Configuration constructConfiguration() {
4642
return configuration;
4743
}
4844

45+
@BeforeEach
46+
public void clearTracker() {
47+
sqlTracker.clear();
48+
}
49+
4950
protected void addServices(StandardServiceRegistryBuilder builder) {
5051
sqlTracker.registerService( builder );
5152
}
@@ -60,12 +61,6 @@ private static boolean filter(String s) {
6061
return false;
6162
}
6263

63-
@Override
64-
public CompletionStage<Void> cleanDb() {
65-
getSessionFactory().close();
66-
return CompletionStages.voidFuture();
67-
}
68-
6964
@Test
7065
public void testBatchingWithPersistAll(VertxTestContext context) {
7166
test( context, openSession()

hibernate-reactive-core/src/test/java/org/hibernate/reactive/CacheTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
package org.hibernate.reactive;
77

88

9-
import java.util.concurrent.CompletionStage;
109

1110
import org.hibernate.annotations.Cache;
1211
import org.hibernate.cfg.Configuration;
1312
import org.hibernate.cfg.Environment;
14-
import org.hibernate.reactive.util.impl.CompletionStages;
1513

14+
import org.junit.jupiter.api.AfterEach;
1615
import org.junit.jupiter.api.Test;
1716

1817
import io.vertx.junit5.VertxTestContext;
@@ -40,10 +39,10 @@ protected Configuration constructConfiguration() {
4039
return configuration;
4140
}
4241

43-
@Override
44-
public CompletionStage<Void> cleanDb() {
42+
@AfterEach
43+
public void cleanDB() {
44+
// We clean the cache after each test this way
4545
getSessionFactory().close();
46-
return CompletionStages.voidFuture();
4746
}
4847

4948
@Test

hibernate-reactive-core/src/test/java/org/hibernate/reactive/CompletionStagesTest.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@
1313
import java.util.List;
1414
import java.util.Queue;
1515
import java.util.concurrent.CompletionStage;
16-
import java.util.concurrent.TimeUnit;
1716
import java.util.stream.IntStream;
1817

19-
import org.junit.jupiter.api.BeforeEach;
2018
import org.junit.jupiter.api.Test;
2119
import org.junit.jupiter.api.TestInstance;
2220
import org.junit.jupiter.api.extension.ExtendWith;
2321

24-
import io.vertx.junit5.Timeout;
2522
import io.vertx.junit5.VertxExtension;
2623
import io.vertx.junit5.VertxTestContext;
2724

@@ -36,16 +33,12 @@
3633
* Tests the utility methods in {@link org.hibernate.reactive.util.impl.CompletionStages}
3734
*/
3835
@ExtendWith(VertxExtension.class)
39-
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
36+
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
4037
public class CompletionStagesTest {
4138

4239
private final Object[] entries = { "a", "b", "c", "d", "e" };
4340
private final List<Object> looped = new ArrayList<>();
4441

45-
@BeforeEach
46-
private void clearLooped() {
47-
looped.clear();
48-
}
4942
@Test
5043
public void testTotalWithIntegers(VertxTestContext context) {
5144
int startInt = 0;
@@ -191,7 +184,6 @@ private static Iterator<Object> iterator(Object[] entries) {
191184
return asList( entries ).iterator();
192185
}
193186

194-
@Timeout(value = 60, timeUnit = TimeUnit.SECONDS)
195187
protected static void test(VertxTestContext context, CompletionStage<?> work) {
196188
work.whenComplete( (res, err) -> {
197189
if ( err != null ) {

hibernate-reactive-core/src/test/java/org/hibernate/reactive/CompositeIdTest.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.concurrent.CompletionStage;
1414

1515
import org.hibernate.reactive.stage.Stage;
16-
import org.hibernate.reactive.util.impl.CompletionStages;
1716

1817
import org.junit.jupiter.api.Assertions;
1918
import org.junit.jupiter.api.Test;
@@ -37,10 +36,9 @@ protected Collection<Class<?>> annotatedEntities() {
3736

3837
private CompletionStage<Void> populateDB() {
3938
return getSessionFactory()
40-
.withSession(
41-
session -> session.persist( new GuineaPig(5, "Aloi", 100) )
42-
.thenCompose( v -> session.flush() )
43-
);
39+
.withTransaction( session -> session
40+
.persist( new GuineaPig( 5, "Aloi", 100 ) )
41+
);
4442
}
4543

4644
private CompletionStage<String> selectNameFromId(Integer id) {
@@ -122,12 +120,10 @@ public void reactiveRemoveTransientEntity(VertxTestContext context) {
122120
)
123121
.thenCompose( v -> selectNameFromId( 5 ) )
124122
.thenAccept( Assertions::assertNull )
125-
.handle((r, e) -> {
126-
Object exception = e;
127-
Assertions.assertNotNull( exception );
128-
return CompletionStages.voidFuture();
129-
} ) //NotNull( e ) )
130-
// .handle((r, e) -> Assertions.assertTrue( e != null))
123+
.handle( (r, e) -> {
124+
assertNotNull( e );
125+
return r;
126+
} )
131127
);
132128
}
133129

hibernate-reactive-core/src/test/java/org/hibernate/reactive/CustomGeneratorTest.java

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,55 +44,62 @@ public void testSequenceGenerator(VertxTestContext context) {
4444
CustomId b = new CustomId();
4545
b.string = "Hello World";
4646

47-
test( context,
47+
test(
48+
context,
4849
openSession()
49-
.thenCompose(s -> s.persist(b).thenCompose(v -> s.flush()))
50-
.thenCompose( v -> openSession() )
51-
.thenCompose( s2 ->
52-
s2.find( CustomId.class, b.getId() )
50+
.thenCompose( s -> s.persist( b ).thenCompose( v -> s.flush() ) )
51+
.thenCompose( v -> openSession() )
52+
.thenCompose( s2 -> s2
53+
.find( CustomId.class, b.getId() )
54+
.thenAccept( bb -> {
55+
assertNotNull( bb );
56+
assertEquals( bb.id, 1100 );
57+
assertEquals( bb.string, b.string );
58+
assertEquals( bb.version, 0 );
59+
60+
bb.string = "Goodbye";
61+
} )
62+
.thenCompose( vv -> s2.flush() )
63+
.thenCompose( vv -> s2.find( CustomId.class, b.getId() ) )
64+
.thenAccept( bt -> {
65+
assertEquals( bt.version, 1 );
66+
} ) )
67+
.thenCompose( v -> openSession() )
68+
.thenCompose( s3 -> s3.find( CustomId.class, b.getId() ) )
5369
.thenAccept( bb -> {
54-
assertNotNull( bb );
55-
assertEquals( bb.id, 1100 );
56-
assertEquals( bb.string, b.string );
57-
assertEquals( bb.version, 0 );
58-
59-
bb.string = "Goodbye";
60-
})
61-
.thenCompose(vv -> s2.flush())
62-
.thenCompose(vv -> s2.find( CustomId.class, b.getId() ))
63-
.thenAccept( bt -> {
64-
assertEquals( bt.version, 1 );
65-
}))
66-
.thenCompose( v -> openSession() )
67-
.thenCompose( s3 -> s3.find( CustomId.class, b.getId() ) )
68-
.thenAccept( bb -> {
69-
assertEquals(bb.version, 1);
70-
assertEquals(bb.string, "Goodbye");
71-
})
70+
assertEquals( bb.version, 1 );
71+
assertEquals( bb.string, "Goodbye" );
72+
} )
7273
);
7374
}
7475

7576
public static class Thousands implements ReactiveIdentifierGenerator<Integer>, Configurable {
7677
int current = 0;
78+
7779
@Override
7880
public CompletionStage<Integer> generate(ReactiveConnectionSupplier session, Object entity) {
7981
current += 1000;
80-
return completedFuture(current);
82+
return completedFuture( current );
8183
}
84+
8285
@Override
8386
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) {
84-
current = Integer.parseInt( params.getProperty("offset", "0") );
87+
current = Integer.parseInt( params.getProperty( "offset", "0" ) );
8588
}
8689
}
8790

8891
@Entity
89-
@GenericGenerator(name="thousands",
90-
strategy="org.hibernate.reactive.CustomGeneratorTest$Thousands",
91-
parameters = @Parameter(name = "offset", value = "100"))
92+
@GenericGenerator(
93+
name = "thousands",
94+
strategy = "org.hibernate.reactive.CustomGeneratorTest$Thousands",
95+
parameters = @Parameter(name = "offset", value = "100")
96+
)
9297
public static class CustomId {
93-
@Id @GeneratedValue(generator = "thousands")
98+
@Id
99+
@GeneratedValue(generator = "thousands")
94100
Integer id;
95-
@Version Integer version;
101+
@Version
102+
Integer version;
96103
String string;
97104

98105
public CustomId() {
@@ -133,12 +140,12 @@ public boolean equals(Object o) {
133140
return false;
134141
}
135142
CustomId customId = (CustomId) o;
136-
return Objects.equals(string, customId.string);
143+
return Objects.equals( string, customId.string );
137144
}
138145

139146
@Override
140147
public int hashCode() {
141-
return Objects.hash(string);
148+
return Objects.hash( string );
142149
}
143150
}
144151
}

0 commit comments

Comments
 (0)