focusing on using autoClose

This commit is contained in:
Rob Austin
2015-02-02 16:15:43 +00:00
parent 66dc092c7b
commit 24e6e5e515
4 changed files with 60 additions and 48 deletions
@@ -203,14 +203,17 @@ public class ChronicleMapTest {
final File persistenceFile = Builder.getPersistenceFile();
for (int i = 0; i < 2; i++) {
ChronicleMap<byte[], byte[]> map = ChronicleMapBuilder.of(byte[].class, byte[]
.class).createPersistedTo(persistenceFile);
try (ChronicleMap<byte[], byte[]> map = ChronicleMapBuilder.of(byte[].class, byte[]
.class).createPersistedTo(persistenceFile)) {
byte[] o = map.get("hello".getBytes());
System.out.println(o == null ? "null" : new String(o));
map.put("hello".getBytes(), "world".getBytes());
byte[] o = map.get("hello".getBytes());
System.out.println(o == null ? "null" : new String(o));
map.put("hello".getBytes(), "world".getBytes());
}
}
persistenceFile.delete();
}
@@ -1880,7 +1883,9 @@ public class ChronicleMapTest {
assertEquals(2, value1.getValue());
}
}
tmpFile.delete();
}
}
@@ -190,24 +190,26 @@ public class EntryCountMapTest {
Random random = new Random(seed);
int counter = minSize + random.nextInt(9999 + maxSize);
final int stride = 1 + random.nextInt(100);
int maxKeySize = "key:".length() +
final int maxKeySize = "key:".length() +
(int) round(log10(moreThanMaxSize(maxSize) * stride + counter)) + 1;
File f = null;
try ( final ChronicleMap<CharSequence, LongValue> map =
getSharedMap(minSize, segments, maxKeySize)) {
f = map.file();
return es.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
return es.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
File f = null;
try (final ChronicleMap<CharSequence, LongValue> map =
getSharedMap(minSize, segments, maxKeySize)) {
f = map.file();
testEntriesMaxSize0(segments, minSize, maxSize, seed, stride, map);
} finally {
if (f != null && f.exists())
f.delete();
return null;
}
});
} finally {
if (f != null && f.exists())
f.delete();
}
}
});
}
void testEntriesMaxSize(int segments, int minSize, int maxSize, int seed) throws IOException {
@@ -48,7 +48,7 @@ public class LargeEntriesTest {
File file = File.createTempFile("largeEntries" + System.currentTimeMillis(), ".deleteme");
file.deleteOnExit();
final ChronicleMap<String, String> map = ChronicleMapBuilder
try (final ChronicleMap<String, String> map = ChronicleMapBuilder
.of(String.class, String.class)
.valueMarshaller(SnappyStringMarshaller.INSTANCE)
.actualSegments(1) // to force an error.
@@ -56,37 +56,38 @@ public class LargeEntriesTest {
.averageKeySize(10)
.averageValueSize(ENTRY_SIZE)
.putReturnsNull(true)
.createPersistedTo(file);
{
warmUpCompression(ENTRY_SIZE);
int threads = 4; //Runtime.getRuntime().availableProcessors();
ExecutorService es = Executors.newFixedThreadPool(threads);
final int block = ENTRIES / threads;
for (int i = 0; i < 3; i++) {
long start = System.currentTimeMillis();
List<Future<?>> futureList = new ArrayList<>();
for (int t = 0; t < threads; t++) {
final int finalT = t;
futureList.add(es.submit(new Runnable() {
@Override
public void run() {
exerciseLargeStrings(map, finalT * block, finalT * block + block,
ENTRY_SIZE);
}
}));
.createPersistedTo(file)) {
{
warmUpCompression(ENTRY_SIZE);
int threads = 4; //Runtime.getRuntime().availableProcessors();
ExecutorService es = Executors.newFixedThreadPool(threads);
final int block = ENTRIES / threads;
for (int i = 0; i < 3; i++) {
long start = System.currentTimeMillis();
List<Future<?>> futureList = new ArrayList<>();
for (int t = 0; t < threads; t++) {
final int finalT = t;
futureList.add(es.submit(new Runnable() {
@Override
public void run() {
exerciseLargeStrings(map, finalT * block, finalT * block + block,
ENTRY_SIZE);
}
}));
}
for (Future<?> future : futureList) {
future.get();
}
long time = System.currentTimeMillis() - start;
long operations = 3;
System.out.printf("Put/Get rate was %.1f MB/s%n",
operations * ENTRIES * ENTRY_SIZE / 1e6 / (time / 1e3));
}
for (Future<?> future : futureList) {
future.get();
}
long time = System.currentTimeMillis() - start;
long operations = 3;
System.out.printf("Put/Get rate was %.1f MB/s%n",
operations * ENTRIES * ENTRY_SIZE / 1e6 / (time / 1e3));
es.shutdown();
}
es.shutdown();
if (es.isTerminated())
map.close();
}
file.delete();
}
private void warmUpCompression(int entrySize) {
@@ -55,8 +55,9 @@ public class TCPSocketReplicationBootStrapTest {
ChronicleMapBuilder<Integer, CharSequence> map2aBuilder =
newTcpSocketShmBuilder(Integer.class, CharSequence.class,
(byte) 2, 8092, new InetSocketAddress("localhost", 8091));
File persistenceFile = getPersistenceFile();
final ChronicleMap<Integer, CharSequence> map2a =
map2aBuilder.createPersistedTo(getPersistenceFile());
map2aBuilder.createPersistedTo(persistenceFile);
map2a.put(10, "EXAMPLE-10"); // this will be the last time that map1 go an update from map2
long lastModificationTime;
@@ -85,6 +86,9 @@ public class TCPSocketReplicationBootStrapTest {
// add data into it
waitTillEqual(5000);
assertEquals("ADDED WHEN DISCONNECTED TO MAP1", map1.get(11));
map2.file().delete();
persistenceFile.delete();
}
@Test