mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Optimize memory in non-persisted case -- don't zero out all memory eagery; remove global mutable state duplication code in VanillaChronicleHash and ReplicatedChronicleMap; make sleep interruptible in OldEntriesCleanup thread; remove old entries cleanup duplicatation tracking; fix bugs
This commit is contained in:
@@ -25,9 +25,12 @@ import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.google.common.collect.Maps.difference;
|
||||
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
*/
|
||||
@@ -59,15 +62,23 @@ public class Builder {
|
||||
return file;
|
||||
}
|
||||
|
||||
public static void waitTillEqual(Map map1, Map map2, int timeOut) {
|
||||
for (int t = 0; t < timeOut; t++) {
|
||||
if (map1.equals(map2))
|
||||
break;
|
||||
try {
|
||||
public static void waitTillEqual(Map map1, Map map2, int timeOutMs) throws InterruptedException {
|
||||
int numberOfTimesTheSame = 0;
|
||||
long startTime = System.currentTimeMillis();
|
||||
for (int t = 0; t < timeOutMs + 100; t++) {
|
||||
// not map1.equals(map2), the reason is described above
|
||||
if (map1.equals(map2)) {
|
||||
numberOfTimesTheSame++;
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
if (numberOfTimesTheSame == 10) {
|
||||
System.out.println("same");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
Thread.sleep(1);
|
||||
if (System.currentTimeMillis() - startTime > timeOutMs)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2015 higherfrequencytrading.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.VanillaGlobalMutableState;
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class GlobalMutableStateTest {
|
||||
|
||||
private String dumpCode;
|
||||
|
||||
@Before
|
||||
public void setDumpCode() {
|
||||
dumpCode = System.getProperty("dvg.dumpCode");
|
||||
System.setProperty("dvg.dumpCode", "true");
|
||||
}
|
||||
|
||||
@After
|
||||
public void unsetDumpCode() {
|
||||
if (dumpCode != null)
|
||||
System.setProperty("dvg.dumpCode", dumpCode);
|
||||
else
|
||||
System.getProperties().remove("dvg.dumpCode");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void globalMutableStateTest() {
|
||||
DataValueClasses.newDirectReference(ReplicatedGlobalMutableState.class);
|
||||
DataValueClasses.newDirectReference(VanillaGlobalMutableState.class);
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
|
||||
public void testIgnoreLateAction(BiConsumer<ChronicleMap<CharSequence, CharSequence>,
|
||||
ChronicleMap<CharSequence, CharSequence>> action)
|
||||
throws IOException {
|
||||
throws IOException, InterruptedException {
|
||||
|
||||
final TimeProvider timeProvider = Mockito.mock(TimeProvider.class);
|
||||
try (ChronicleMap<CharSequence, CharSequence> map =
|
||||
@@ -97,7 +97,7 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreALatePut() throws IOException {
|
||||
public void testIgnoreALatePut() throws IOException, InterruptedException {
|
||||
testIgnoreLateAction((m1, m2) -> {
|
||||
m2.put("key-1", "value-2");
|
||||
assertEquals("value-2", m2.get("key-1"));
|
||||
@@ -137,7 +137,7 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreALateReplace() throws IOException {
|
||||
public void testIgnoreALateReplace() throws IOException, InterruptedException {
|
||||
testIgnoreLateAction((m1, m2) -> {
|
||||
// in order to be able to call replace() "locally"
|
||||
m2.put("key-1", "dummy");
|
||||
@@ -147,7 +147,7 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreALateReplaceWithValue() throws IOException {
|
||||
public void testIgnoreALateReplaceWithValue() throws IOException, InterruptedException {
|
||||
testIgnoreLateAction((m1, m2) -> {
|
||||
// in order to be able to call replace() "locally"
|
||||
m2.put("key-1", "dummy");
|
||||
@@ -157,7 +157,7 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreALateRemoveWithValue() throws IOException {
|
||||
public void testIgnoreALateRemoveWithValue() throws IOException, InterruptedException {
|
||||
testIgnoreLateAction((m1, m2) -> {
|
||||
// in order to be able to call remove() "locally"
|
||||
m2.put("key-1", "dummy");
|
||||
@@ -167,7 +167,7 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreALateRemove() throws IOException {
|
||||
public void testIgnoreALateRemove() throws IOException, InterruptedException {
|
||||
testIgnoreLateAction((m1, m2) -> {
|
||||
// in order to be able to call remove() "locally"
|
||||
m2.put("key-1", "dummy");
|
||||
@@ -177,7 +177,7 @@ public class TimeBasedReplicationTest extends JSR166TestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveFollowedByLatePut() throws IOException {
|
||||
public void testRemoveFollowedByLatePut() throws IOException, InterruptedException {
|
||||
|
||||
final TimeProvider timeProvider = Mockito.mock(TimeProvider.class);
|
||||
try (ChronicleMap<CharSequence, CharSequence> map =
|
||||
|
||||
Reference in New Issue
Block a user