Merge branch 'master' into feature/query-cache-1427

This commit is contained in:
rob bygrave committed 2018-06-16 00:09:25 +12:00
commit 5adbebaf6e
6 files changed
+118 -3

No files matched your search

@@ -1,15 +1,26 @@
package io.ebean;
import org.junit.After;
import org.junit.Test;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
import java.time.Clock;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class ExtendedServerTest extends BaseTestCase {
@After
public void cleanup() {
Ebean.getDefaultServer()
.extended()
.setClock(Clock.systemUTC());
}
@Test
public void findList() {
@@ -38,4 +49,47 @@ public class ExtendedServerTest extends BaseTestCase {
}
}
@Test
public void mockClock() {
EbeanServer server = Ebean.getDefaultServer();
final Instant snapshot = Instant.now();
Instant backedSnapshot = snapshot.minus(1, ChronoUnit.DAYS);
Clock snapshotClock = Clock.fixed(backedSnapshot, Clock.systemUTC().getZone());
server.extended().setClock(snapshotClock);
ResetBasicData.reset();
int count = server
.find(Customer.class)
.where()
.gt("cretime", snapshot)
.findCount();
assertThat(count).isEqualTo(0);
int count2 = server
.find(Customer.class)
.where()
.ge("cretime", backedSnapshot)
.findCount();
assertThat(count2).isGreaterThan(0);
int count3 = server
.find(Customer.class)
.where()
.gt("updtime", snapshot)
.findCount();
assertThat(count3).isEqualTo(0);
int count4 = server
.find(Customer.class)
.where()
.ge("updtime", backedSnapshot)
.findCount();
assertThat(count4).isGreaterThan(0);
}
}
@@ -55,6 +55,7 @@ import io.ebeaninternal.server.transaction.RemoteTransactionEvent;
import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceException;
import java.lang.reflect.Type;
import java.time.Clock;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -85,6 +86,16 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
return this;
}
@Override
public long clockNow() {
return System.currentTimeMillis();
}
@Override
public void setClock(Clock clock) {
}
@Override
public SpiLogManager log() {
return null;