Skip to content

Commit

Permalink
Merge pull request #3519 from FOCONIS/no-codechange-test-cleanup
Browse files Browse the repository at this point in the history
No productive code change: cleanup basic test data
  • Loading branch information
rbygrave authored Nov 7, 2024
2 parents 7035b4c + 59ed0bb commit 103e832
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,22 @@ public void batchFlush() {

for (int i = 0; i < 3; i++) {
Customer customer = ResetBasicData.createCustomer("BatchFlushPreInsert " + i, null, null, 3);
customer.addContact(new Contact("Fred" + i, "Blue"));
customer.addContact(new Contact("BatchFlush" + i, "Blue"));
customers.add(customer);
}

for (int i = 3; i < 6; i++) {
Customer customer = ResetBasicData.createCustomer("BatchFlushPostInsert " + i, null, null, 3);
customer.addContact(new Contact("Fred" + i, "Blue"));
customer.addContact(new Contact("BatchFlush" + i, "Blue"));
customers.add(customer);
}

DB.saveAll(customers);

txn.commit();
} finally {
DB.find(Customer.class).where().startsWith("name", "BatchFlush").delete();
DB.find(Contact.class).where().startsWith("firstName", "BatchFlush").startsWith("lastName", "Blue").delete();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,30 @@ public void testBeanCacheWithLazyLoading() {

DB.save(contact);

// Only get two properties, so we have to lazy-load later
final Contact contactDb = DB.find(Contact.class).where().eq("email", "[email protected]").select("email,lastName").findOne();
assertThat(contactDb).isNotNull();
LoggedSql.start();
contactDb.setLastName("Buttonnnn");
List<String> sql = LoggedSql.collect();
assertThat(sql).isEmpty(); // setter did not trigger lazy load
try {

// trigger lazy load
assertThat(contactDb.getPhone()).isEqualTo("1234567890");
sql = LoggedSql.collect();
assertThat(sql).isNotEmpty(); // Lazy-load took place
// Only get two properties, so we have to lazy-load later
final Contact contactDb = DB.find(Contact.class).where().eq("email", "[email protected]").select("email,lastName").findOne();
assertThat(contactDb).isNotNull();
LoggedSql.start();
contactDb.setLastName("Buttonnnn");
List<String> sql = LoggedSql.collect();
assertThat(sql).isEmpty(); // setter did not trigger lazy load

final Contact contactDb2 = DB.find(Contact.class).where().eq("email", "[email protected]").select("email,lastName").findOne();
sql = LoggedSql.stop();
assertThat(sql).isEmpty(); // We expect that the bean was loaded from cache
assertThat(contactDb2).isNotNull();
assertThat(contactDb2.getLastName()).isEqualTo("Button");
// trigger lazy load
assertThat(contactDb.getPhone()).isEqualTo("1234567890");
sql = LoggedSql.collect();
assertThat(sql).isNotEmpty(); // Lazy-load took place

final Contact contactDb2 = DB.find(Contact.class).where().eq("email", "[email protected]").select("email,lastName").findOne();
sql = LoggedSql.stop();
assertThat(sql).isEmpty(); // We expect that the bean was loaded from cache
assertThat(contactDb2).isNotNull();
assertThat(contactDb2.getLastName()).isEqualTo("Button");
} finally {
DB.delete(customer);
DB.find(Contact.class).where().eq("email", "[email protected]").delete();
}
}

}
15 changes: 10 additions & 5 deletions ebean-test/src/test/java/org/tests/model/basic/ResetBasicData.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static synchronized void reset() {
// OK, test data not modified
outputCustomerIds();
} else {
outputState();
outputState(true);
}
return;
}
Expand All @@ -45,11 +45,11 @@ public static synchronized void reset() {
me.insertProducts();
me.insertTestCustAndOrders();
});
outputState();
outputState(false);
runOnce = true;
}

private static void outputState() {
private static void outputState(boolean warning) {
StringBuilder sb = new StringBuilder();
sb.append("CustomerIds:");
server.find(Customer.class).findEach(c -> sb.append(' ').append(c.getId()));
Expand All @@ -59,8 +59,13 @@ private static void outputState() {
server.find(Country.class).findEach(c -> sb.append(' ').append(c.getCode()));
sb.append(", Products:");
server.find(Product.class).findEach(c -> sb.append(' ').append(c.getId()));
System.err.println("WARNING: basic test data was modified. Current content:");
System.err.println(sb);
if (warning) {
System.err.println("WARNING: basic test data was modified. Current content:");
System.err.println(sb);
} else {
System.out.println("ResetBasicData. basic test data was initialized Current content:");
System.out.println(sb);
}
}

private static void outputCustomerIds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ public void implicit_save_expect_threadScopeCleanup() {
cust.setName("Roland");
DB.save(cust);

assertThat(getInScopeTransaction()).isNull();
try {
assertThat(getInScopeTransaction()).isNull();
} finally {
DB.delete(cust);
}
}

@ForPlatform(Platform.H2)
Expand Down

0 comments on commit 103e832

Please sign in to comment.