mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
No effective change - add a test for saveAll() with existing batch mode on
Assert that it does not flush the batch. We want the batch to continue and flush normally.
This commit is contained in:
@@ -53,6 +53,45 @@ public class EbeanServer_saveAllTest extends BaseTestCase {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveAll_withExistingBatch_doesNotTriggerFlush() {
|
||||
|
||||
EbeanServer server = Ebean.getDefaultServer();
|
||||
|
||||
Transaction transaction = server.beginTransaction();
|
||||
transaction.setBatch(PersistBatch.ALL);
|
||||
try {
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
for (EBasicVer bean : beans(2)) {
|
||||
server.save(bean);
|
||||
}
|
||||
|
||||
// jdbc batch, no sql yet
|
||||
assertThat(LoggedSqlCollector.current()).isEmpty();
|
||||
|
||||
server.saveAll(beans(3));
|
||||
|
||||
// still batch, no sql yet
|
||||
assertThat(LoggedSqlCollector.current()).isEmpty();
|
||||
|
||||
for (EBasicVer bean : beans(2)) {
|
||||
server.save(bean);
|
||||
}
|
||||
// still batch, no sql yet
|
||||
assertThat(LoggedSqlCollector.current()).isEmpty();
|
||||
|
||||
// flush now
|
||||
transaction.commit();
|
||||
|
||||
// and we have our SQL from jdbc batch flush
|
||||
assertThat(LoggedSqlCollector.stop()).isNotEmpty();
|
||||
|
||||
} finally {
|
||||
transaction.end();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveAll_withTransaction() {
|
||||
|
||||
@@ -52,6 +52,10 @@ public class LoggedSqlCollector {
|
||||
return basicAppender.collectEnd();
|
||||
}
|
||||
|
||||
public static List<String> current() {
|
||||
return basicAppender.collectContinue();
|
||||
}
|
||||
|
||||
private static class BasicAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
|
||||
|
||||
List<String> messages = new ArrayList<>();
|
||||
@@ -85,5 +89,14 @@ public class LoggedSqlCollector {
|
||||
return tempMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the collected SQL and continue.
|
||||
*/
|
||||
List<String> collectContinue() {
|
||||
List<String> tempMessages = messages;
|
||||
messages = new ArrayList<>();
|
||||
return tempMessages;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user