提交 966c6c1a authored 作者: Thomas Mueller Graf's avatar Thomas Mueller Graf

Fix test cases for Windows

上级 278e6e81
...@@ -117,6 +117,7 @@ public class TestConcurrentLinkedList extends TestBase { ...@@ -117,6 +117,7 @@ public class TestConcurrentLinkedList extends TestBase {
@Override @Override
public void call() { public void call() {
while (!stop) { while (!stop) {
Thread.yield();
if (size.get() < 10) { if (size.get() < 10) {
test.add(counter.getAndIncrement()); test.add(counter.getAndIncrement());
size.getAndIncrement(); size.getAndIncrement();
...@@ -126,6 +127,7 @@ public class TestConcurrentLinkedList extends TestBase { ...@@ -126,6 +127,7 @@ public class TestConcurrentLinkedList extends TestBase {
}; };
task.execute(); task.execute();
for (int i = 0; i < 1000000;) { for (int i = 0; i < 1000000;) {
Thread.yield();
Integer x = test.peekFirst(); Integer x = test.peekFirst();
if (x == null) { if (x == null) {
continue; continue;
......
...@@ -434,16 +434,9 @@ public class TestMVStore extends TestBase { ...@@ -434,16 +434,9 @@ public class TestMVStore extends TestBase {
assertEquals("1", header.get("format").toString()); assertEquals("1", header.get("format").toString());
header.put("formatRead", "1"); header.put("formatRead", "1");
header.put("format", "2"); header.put("format", "2");
forceWriteStoreHeader(s);
MVMap<Integer, String> m = s.openMap("data"); MVMap<Integer, String> m = s.openMap("data");
// this is to ensure the file header is overwritten forceWriteStoreHeader(s);
// the header is written at least every 20 commits
for (int i = 0; i < 30; i++) {
m.put(0, "Hello World " + i);
s.commit();
if (i > 5) {
s.setRetentionTime(0);
}
}
m.put(0, "Hello World"); m.put(0, "Hello World");
s.close(); s.close();
try { try {
...@@ -531,7 +524,7 @@ public class TestMVStore extends TestBase { ...@@ -531,7 +524,7 @@ public class TestMVStore extends TestBase {
if (exRef.get() != null) { if (exRef.get() != null) {
break; break;
} }
Thread.sleep(10); sleep(10);
} }
Throwable e = exRef.get(); Throwable e = exRef.get();
assertTrue(e != null); assertTrue(e != null);
...@@ -627,7 +620,7 @@ public class TestMVStore extends TestBase { ...@@ -627,7 +620,7 @@ public class TestMVStore extends TestBase {
FileUtils.delete(fileName); FileUtils.delete(fileName);
} }
private void testWriteDelay() throws InterruptedException { private void testWriteDelay() {
String fileName = getBaseDir() + "/" + getTestName(); String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName); FileUtils.delete(fileName);
MVStore s; MVStore s;
...@@ -678,7 +671,7 @@ public class TestMVStore extends TestBase { ...@@ -678,7 +671,7 @@ public class TestMVStore extends TestBase {
if (diff > 1000) { if (diff > 1000) {
fail(); fail();
} }
Thread.sleep(10); sleep(10);
} }
s.closeImmediately(); s.closeImmediately();
...@@ -764,15 +757,7 @@ public class TestMVStore extends TestBase { ...@@ -764,15 +757,7 @@ public class TestMVStore extends TestBase {
int format = Integer.parseInt(header.get("format").toString()); int format = Integer.parseInt(header.get("format").toString());
assertEquals(1, format); assertEquals(1, format);
header.put("format", Integer.toString(format + 1)); header.put("format", Integer.toString(format + 1));
// this is to ensure the file header is overwritten forceWriteStoreHeader(s);
// the header is written at least every 20 commits
for (int i = 0; i < 30; i++) {
if (i > 5) {
s.setRetentionTime(0);
}
m.put(10, 100 * i);
s.commit();
}
s.close(); s.close();
try { try {
openStore(fileName).close(); openStore(fileName).close();
...@@ -904,23 +889,44 @@ public class TestMVStore extends TestBase { ...@@ -904,23 +889,44 @@ public class TestMVStore extends TestBase {
long creationTime = (Long) m.get("created"); long creationTime = (Long) m.get("created");
assertTrue(Math.abs(time - creationTime) < 100); assertTrue(Math.abs(time - creationTime) < 100);
m.put("test", "123"); m.put("test", "123");
MVMap<Integer, Integer> map = s.openMap("test"); forceWriteStoreHeader(s);
s.close();
s = openStore(fileName);
Object test = s.getStoreHeader().get("test");
assertFalse(test == null);
assertEquals("123", test.toString());
s.close();
}
private static void forceWriteStoreHeader(MVStore s) {
MVMap<Integer, Integer> map = s.openMap("dummy");
map.put(10, 100); map.put(10, 100);
// this is to ensure the file header is overwritten // this is to ensure the file header is overwritten
// the header is written at least every 20 commits // the header is written at least every 20 commits
for (int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
if (i > 5) { if (i > 5) {
s.setRetentionTime(0); s.setRetentionTime(0);
// ensure that the next save time is different,
// so that blocks can be reclaimed
// (on Windows, resolution is 10 ms)
sleep(1);
} }
map.put(10, 110); map.put(10, 110);
s.commit(); s.commit();
} }
s.close(); s.removeMap(map);
s = openStore(fileName); s.commit();
Object test = s.getStoreHeader().get("test"); }
assertFalse(test == null);
assertEquals("123", test.toString()); private static void sleep(long ms) {
s.close(); // on Windows, need to sleep in some cases,
// mainly because the milliseconds resolution of
// System.currentTimeMillis is 10 ms.
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
// ignore
}
} }
private void testFileHeaderCorruption() throws Exception { private void testFileHeaderCorruption() throws Exception {
...@@ -939,7 +945,7 @@ public class TestMVStore extends TestBase { ...@@ -939,7 +945,7 @@ public class TestMVStore extends TestBase {
} }
FileStore fs = s.getFileStore(); FileStore fs = s.getFileStore();
long size = fs.getFile().size(); long size = fs.getFile().size();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 100; i++) {
map = s.openMap("test" + i); map = s.openMap("test" + i);
s.removeMap(map); s.removeMap(map);
s.commit(); s.commit();
...@@ -1387,10 +1393,11 @@ public class TestMVStore extends TestBase { ...@@ -1387,10 +1393,11 @@ public class TestMVStore extends TestBase {
m = s.openMap("data"); m = s.openMap("data");
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
if (i % 4 != 0) { if (i % 4 != 0) {
sleep(2);
m.remove(i); m.remove(i);
s.commit();
} }
} }
s.commit();
assertTrue(s.compact(100, 50 * 1024)); assertTrue(s.compact(100, 50 * 1024));
s.close(); s.close();
long len2 = FileUtils.size(fileName); long len2 = FileUtils.size(fileName);
...@@ -1762,6 +1769,7 @@ public class TestMVStore extends TestBase { ...@@ -1762,6 +1769,7 @@ public class TestMVStore extends TestBase {
m = s.openMap("data"); m = s.openMap("data");
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
sleep(1);
boolean result = s.compact(50, 50 * 1024); boolean result = s.compact(50, 50 * 1024);
if (!result) { if (!result) {
break; break;
...@@ -1790,6 +1798,7 @@ public class TestMVStore extends TestBase { ...@@ -1790,6 +1798,7 @@ public class TestMVStore extends TestBase {
FileUtils.delete(fileName); FileUtils.delete(fileName);
long initialLength = 0; long initialLength = 0;
for (int j = 0; j < 20; j++) { for (int j = 0; j < 20; j++) {
sleep(2);
MVStore s = openStore(fileName); MVStore s = openStore(fileName);
s.setRetentionTime(0); s.setRetentionTime(0);
MVMap<Integer, String> m = s.openMap("data"); MVMap<Integer, String> m = s.openMap("data");
...@@ -1831,6 +1840,7 @@ public class TestMVStore extends TestBase { ...@@ -1831,6 +1840,7 @@ public class TestMVStore extends TestBase {
FileUtils.delete(fileName); FileUtils.delete(fileName);
long initialLength = 0; long initialLength = 0;
for (int j = 0; j < 20; j++) { for (int j = 0; j < 20; j++) {
sleep(2);
MVStore s = openStore(fileName); MVStore s = openStore(fileName);
s.setRetentionTime(0); s.setRetentionTime(0);
MVMap<Integer, String> m = s.openMap("data"); MVMap<Integer, String> m = s.openMap("data");
...@@ -1848,7 +1858,7 @@ public class TestMVStore extends TestBase { ...@@ -1848,7 +1858,7 @@ public class TestMVStore extends TestBase {
initialLength = len; initialLength = len;
} else { } else {
assertTrue("len: " + len + " initial: " + initialLength + " j: " + j, assertTrue("len: " + len + " initial: " + initialLength + " j: " + j,
len <= initialLength * 2); len <= initialLength * 5);
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论