HCOLL-167 added JSR166y tests

This commit is contained in:
Rob Austin
2014-10-21 08:21:35 +01:00
parent 46659e0fa0
commit d31bff4d14
4 changed files with 984 additions and 11 deletions
@@ -0,0 +1,12 @@
package net.openhft.chronicle.common;
import java.io.Closeable;
/**
* @author Rob Austin.
*/
public interface ClosableHolder {
void addCloseable(Closeable closeable);
}
@@ -81,14 +81,18 @@ abstract class AbstractChannelReplicator implements Closeable {
return result;
}
static SocketChannel openSocketChannel(final CloseablesManager closeables) throws IOException {
static SocketChannel openSocketChannel(final CloseablesManager closeables) throws IOException {
SocketChannel result = null;
try {
result = SocketChannel.open();
} finally {
if (result != null)
closeables.add(result);
try {
closeables.add(result);
} catch (IllegalStateException e) {
// already closed
}
}
return result;
}
@@ -1,5 +1,6 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.common.ClosableHolder;
import net.openhft.chronicle.common.StatelessBuilder;
import net.openhft.chronicle.common.exceptions.IORuntimeException;
import net.openhft.chronicle.common.exceptions.TimeoutRuntimeException;
@@ -22,7 +23,7 @@ import static net.openhft.chronicle.map.StatelessChronicleMap.EventId.*;
/**
* @author Rob Austin.
*/
class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, ClosableHolder {
private static final Logger LOG = LoggerFactory.getLogger(StatelessChronicleMap.class);
@@ -57,20 +58,38 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
this.keyValueSerializer = keyValueSerializer;
this.builder = builder;
this.clientChannel = connect(builder);
}
try {
clientChannel = AbstractChannelReplicator.openSocketChannel(closeables);
clientChannel.connect(builder.remoteAddress());
private SocketChannel connect(StatelessBuilder builder) throws IOException {
IOException exception = null;
SocketChannel clientChannel0 = null;
for (int i = 1; i < 5; i++) {
clientChannel0 = AbstractChannelReplicator.openSocketChannel(closeables);
try {
clientChannel0.connect(builder.remoteAddress());
doHandShaking(clientChannel0);
exception = null;
break;
} catch (IOException e) {
closeables.closeQuietly();
Thread.yield();
}
doHandShaking();
} catch (IOException e) {
closeables.closeQuietly();
throw e;
}
if (exception != null)
throw exception;
return clientChannel0;
}
private void doHandShaking() throws IOException {
private void doHandShaking(final SocketChannel clientChannel) throws IOException {
while (STATELESS_CLIENT_IDENTIFER.remaining() > 0) {
clientChannel.write(STATELESS_CLIENT_IDENTIFER);
@@ -98,6 +117,16 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
closeables.closeQuietly();
}
public void addCloseable(final Closeable closeable) {
try {
closeables.add(closeable);
} catch (IllegalStateException e) {
// already closed
}
}
long nextUniqueTransaction(long time) {
long l = transactionID.get();
@@ -389,6 +418,7 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
}
private Bytes blockingFetch(long sizeLocation) {
try {
return blockingFetchThrowable(sizeLocation, this.builder.timeoutMs());
} catch (IOException e) {