|
8 | 8 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; |
9 | 9 | import org.hibernate.cfg.AvailableSettings; |
10 | 10 | import org.hibernate.cfg.Configuration; |
| 11 | +import org.hibernate.reactive.mutiny.Mutiny; |
11 | 12 | import org.hibernate.reactive.mutiny.impl.MutinySessionImpl; |
12 | 13 | import org.hibernate.reactive.mutiny.impl.MutinyStatelessSessionImpl; |
13 | 14 | import org.hibernate.reactive.pool.BatchingConnection; |
14 | 15 | import org.hibernate.reactive.pool.ReactiveConnection; |
15 | 16 | import org.hibernate.reactive.pool.impl.SqlClientConnection; |
| 17 | +import org.hibernate.reactive.stage.Stage; |
16 | 18 | import org.hibernate.reactive.stage.impl.StageSessionImpl; |
17 | 19 | import org.hibernate.reactive.stage.impl.StageStatelessSessionImpl; |
18 | 20 | import org.hibernate.reactive.testing.SqlStatementTracker; |
@@ -85,6 +87,56 @@ protected void assertConnectionIsLazy(ReactiveConnection connection, boolean sta |
85 | 87 | .isEqualTo( org.hibernate.reactive.pool.impl.SqlClientPool.class.getName() + "$ProxyConnection" ); |
86 | 88 | } |
87 | 89 |
|
| 90 | + @Test |
| 91 | + public void testBatchingWithPersistAllAndProxyConnection(VertxTestContext context) { |
| 92 | + Stage.Session session = getSessionFactory().createSession(); |
| 93 | + test( context, session |
| 94 | + .persist( |
| 95 | + new GuineaPig( 11, "One" ), |
| 96 | + new GuineaPig( 22, "Two" ), |
| 97 | + new GuineaPig( 33, "Three" ) |
| 98 | + ) |
| 99 | + // Auto-flush |
| 100 | + .thenCompose( v -> session |
| 101 | + .createSelectionQuery( "select name from GuineaPig", String.class ) |
| 102 | + .getResultList() |
| 103 | + .thenAccept( names -> { |
| 104 | + assertThat( names ).containsExactlyInAnyOrder( "One", "Two", "Three" ); |
| 105 | + assertThat( sqlTracker.getLoggedQueries() ).hasSize( 1 ); |
| 106 | + // Parameters are different for different dbs, so we cannot do an exact match |
| 107 | + assertThat( sqlTracker.getLoggedQueries().get( 0 ) ) |
| 108 | + .startsWith( "insert into pig (name,version,id) values " ); |
| 109 | + sqlTracker.clear(); |
| 110 | + } ) |
| 111 | + ) |
| 112 | + ); |
| 113 | + } |
| 114 | + |
| 115 | + @Test |
| 116 | + public void testBatchingWithPersistAllAndProxyConnectionAndMutiny(VertxTestContext context) { |
| 117 | + Mutiny.Session session = getMutinySessionFactory().createSession(); |
| 118 | + test( context, session |
| 119 | + .persistAll( |
| 120 | + new GuineaPig( 11, "One" ), |
| 121 | + new GuineaPig( 22, "Two" ), |
| 122 | + new GuineaPig( 33, "Three" ) |
| 123 | + ) |
| 124 | + // Auto-flush |
| 125 | + .chain( v -> session |
| 126 | + .createSelectionQuery( "select name from GuineaPig", String.class ) |
| 127 | + .getResultList() |
| 128 | + .invoke( names -> { |
| 129 | + assertThat( names ).containsExactlyInAnyOrder( "One", "Two", "Three" ); |
| 130 | + assertThat( sqlTracker.getLoggedQueries() ).hasSize( 1 ); |
| 131 | + // Parameters are different for different dbs, so we cannot do an exact match |
| 132 | + assertThat( sqlTracker.getLoggedQueries().get( 0 ) ) |
| 133 | + .startsWith( "insert into pig (name,version,id) values " ); |
| 134 | + sqlTracker.clear(); |
| 135 | + } ) |
| 136 | + ) |
| 137 | + ); |
| 138 | + } |
| 139 | + |
88 | 140 | @Test |
89 | 141 | public void testBatchingWithPersistAll(VertxTestContext context) { |
90 | 142 | test( context, openSession().thenCompose( s -> s |
|
0 commit comments