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:
rob bygrave
2017-09-09 14:14:57 +12:00
parent ef05b81014
commit 84d3578e33
2 changed files with 52 additions and 0 deletions
@@ -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;
}
}
}