mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Refactor TableModState to use nanoTime refactor (#1720)
* #1719 - Refactor TableModState to use nanoTime * Tests only - reduce logging
This commit is contained in:
@@ -4,13 +4,10 @@ import io.ebean.cache.ServerCacheFactory;
|
||||
import io.ebean.cache.ServerCacheOptions;
|
||||
import io.ebean.cache.ServerCacheType;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebeaninternal.server.core.ClockService;
|
||||
import io.ebeaninternal.server.transaction.TableModState;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.Clock;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -25,7 +22,7 @@ public class DefaultCacheHolderTest {
|
||||
private CacheManagerOptions options() {
|
||||
return new CacheManagerOptions(null, new ServerConfig(), true)
|
||||
.with(defaultOptions, defaultOptions)
|
||||
.with(cacheFactory, new TableModState(new ClockService(Clock.systemUTC())));
|
||||
.with(cacheFactory, new TableModState());
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-7
@@ -41,11 +41,10 @@ public class BinaryTransactionEventReadWriteTest extends BaseTestCase {
|
||||
|
||||
RemoteTransactionEvent event = new RemoteTransactionEvent("db");
|
||||
|
||||
long timestamp = System.currentTimeMillis();
|
||||
Set<String> tables = new HashSet<>();
|
||||
Collections.addAll(tables, "one", "two", "three");
|
||||
|
||||
event.addRemoteTableMod(new RemoteTableMod(timestamp, tables));
|
||||
event.addRemoteTableMod(new RemoteTableMod(tables));
|
||||
event.addRemoteCacheEvent(new RemoteCacheEvent(Customer.class));
|
||||
|
||||
event.addTableIUD(new TransactionEventTable.TableIUD("foo", true, false, true));
|
||||
@@ -70,7 +69,6 @@ public class BinaryTransactionEventReadWriteTest extends BaseTestCase {
|
||||
|
||||
// table mod
|
||||
RemoteTableMod remoteTableMod = read.getRemoteTableMod();
|
||||
assertThat(remoteTableMod.getTimestamp()).isEqualTo(timestamp);
|
||||
assertThat(remoteTableMod.getTables()).isEqualTo(tables);
|
||||
|
||||
// Bean persist ids
|
||||
@@ -84,18 +82,15 @@ public class BinaryTransactionEventReadWriteTest extends BaseTestCase {
|
||||
|
||||
RemoteTransactionEvent event = new RemoteTransactionEvent("db");
|
||||
|
||||
long timestamp = System.currentTimeMillis();
|
||||
Set<String> tables = new HashSet<>();
|
||||
Collections.addAll(tables, "one", "two", "three");
|
||||
|
||||
event.addRemoteTableMod(new RemoteTableMod(timestamp, tables));
|
||||
event.addRemoteTableMod(new RemoteTableMod(tables));
|
||||
|
||||
byte[] binaryMessage = event.writeBinaryAsBytes(256);
|
||||
RemoteTransactionEvent read = reader.read(binaryMessage);
|
||||
|
||||
RemoteTableMod remoteTableMod = read.getRemoteTableMod();
|
||||
|
||||
assertThat(remoteTableMod.getTimestamp()).isEqualTo(timestamp);
|
||||
assertThat(remoteTableMod.getTables()).isEqualTo(tables);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
package io.ebeaninternal.server.transaction;
|
||||
|
||||
import io.ebeaninternal.server.core.ClockService;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TableModStateTest {
|
||||
|
||||
private TableModState tableModState = new TableModState(new ClockService(Clock.systemUTC()));
|
||||
private TableModState tableModState = new TableModState();
|
||||
|
||||
@Test
|
||||
public void isValid() {
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
long before = System.nanoTime();
|
||||
|
||||
tableModState.touch(setOf("one", "two", "three"), now);
|
||||
tableModState.touch(setOf("one", "two", "three"));
|
||||
|
||||
long after = System.nanoTime();
|
||||
|
||||
// empty
|
||||
assertTrue(tableModState.isValid(Collections.emptySet(), 12L));
|
||||
@@ -28,13 +29,13 @@ public class TableModStateTest {
|
||||
assertTrue(tableModState.isValid(setOf("noEntry"), 12L));
|
||||
|
||||
// later timestamp
|
||||
assertTrue(tableModState.isValid(setOf("one"), now + 1));
|
||||
assertTrue(tableModState.isValid(setOf("one", "two", "noEntry"), now + 1));
|
||||
assertTrue(tableModState.isValid(setOf("one"), after));
|
||||
assertTrue(tableModState.isValid(setOf("one", "two", "noEntry"), after));
|
||||
|
||||
// invalid
|
||||
assertFalse(tableModState.isValid(setOf("one"), now - 1));
|
||||
assertFalse(tableModState.isValid(setOf("one", "two"), now - 1));
|
||||
assertFalse(tableModState.isValid(setOf("three", "two"), now - 1));
|
||||
assertFalse(tableModState.isValid(setOf("one"), before));
|
||||
assertFalse(tableModState.isValid(setOf("one", "two"), before));
|
||||
assertFalse(tableModState.isValid(setOf("three", "two"), before));
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user