mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-218 ReplicatedChronicleMapTest appears to use too much resources. reduced resources used by this test - ( plus a few other changes )
This commit is contained in:
@@ -80,19 +80,35 @@ abstract class AbstractChannelReplicator implements Closeable {
|
||||
}
|
||||
|
||||
Selector openSelector(final CloseablesManager closeables) throws IOException {
|
||||
Selector result = null;
|
||||
try {
|
||||
if (useOptimizedSelectedKeys) {
|
||||
Selector selector = Selector.open();
|
||||
closeables.add(selector);
|
||||
result = openSelector(selector);
|
||||
} else
|
||||
result = Selector.open();
|
||||
|
||||
} finally {
|
||||
if (result != null)
|
||||
closeables.add(result);
|
||||
Selector result = Selector.open();
|
||||
closeables.add(result);
|
||||
|
||||
if (useOptimizedSelectedKeys) {
|
||||
closeables.add(new Closeable() {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
{
|
||||
SelectionKey[] keys = selectedKeys.flip();
|
||||
for (int i = 0; i < keys.length && keys[i] != null; i++) {
|
||||
keys[i] = null;
|
||||
}
|
||||
}
|
||||
{
|
||||
SelectionKey[] keys = selectedKeys.flip();
|
||||
for (int i = 0; i < keys.length && keys[i] != null; i++) {
|
||||
keys[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
return openSelector(result);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -183,7 +199,7 @@ abstract class AbstractChannelReplicator implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
abstract void process() throws IOException;
|
||||
abstract void processEvent() throws IOException;
|
||||
|
||||
final void start() {
|
||||
executorService.execute(
|
||||
@@ -191,7 +207,7 @@ abstract class AbstractChannelReplicator implements Closeable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
process();
|
||||
processEvent();
|
||||
} catch (Exception e) {
|
||||
LOG.error("", e);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ final class TcpReplicator extends AbstractChannelReplicator implements Closeable
|
||||
}
|
||||
|
||||
@Override
|
||||
void process() throws IOException {
|
||||
void processEvent() throws IOException {
|
||||
try {
|
||||
final InetSocketAddress serverInetSocketAddress = new InetSocketAddress(replicationConfig
|
||||
.serverPort());
|
||||
@@ -175,18 +175,22 @@ final class TcpReplicator extends AbstractChannelReplicator implements Closeable
|
||||
|
||||
if (keys.length == 0)
|
||||
continue;
|
||||
try {
|
||||
for (int i = 0; i< keys.length && keys[i] != null; i++) {
|
||||
final SelectionKey key = keys[i];
|
||||
|
||||
try {
|
||||
processKey(approxTime, key);
|
||||
} catch (BufferUnderflowException e) {
|
||||
if (!isClosed)
|
||||
LOG.error("", e);
|
||||
}
|
||||
|
||||
for (int i = 0; ; i++) {
|
||||
final SelectionKey key = keys[i];
|
||||
if (key == null)
|
||||
break;
|
||||
try {
|
||||
processKey(approxTime, key);
|
||||
} catch (BufferUnderflowException e) {
|
||||
if (!isClosed)
|
||||
LOG.error("", e);
|
||||
}
|
||||
|
||||
} finally {
|
||||
for (int i = 0; i< keys.length && keys[i] != null; i++) {
|
||||
keys[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -207,7 +211,7 @@ final class TcpReplicator extends AbstractChannelReplicator implements Closeable
|
||||
} catch (Exception e) {
|
||||
LOG.error("", e);
|
||||
} finally {
|
||||
selectedKeys = null;
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("closing name=" + name);
|
||||
if (!isClosed) {
|
||||
|
||||
@@ -104,7 +104,7 @@ class UdpChannelReplicator extends AbstractChannelReplicator implements Replica.
|
||||
* binds to the server socket and process data This method will block until interrupted
|
||||
*/
|
||||
@Override
|
||||
void process() throws IOException {
|
||||
void processEvent() throws IOException {
|
||||
|
||||
connectClient().register(selector, OP_READ);
|
||||
serverConnector.connectLater();
|
||||
|
||||
@@ -46,7 +46,6 @@ public class ChannelReplicationTest {
|
||||
private ReplicationHub hubA;
|
||||
private ReplicationHub hubB;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
{
|
||||
@@ -59,7 +58,8 @@ public class ChannelReplicationTest {
|
||||
.createWithId((byte) 1);
|
||||
|
||||
map1a = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.entries(1000)
|
||||
.entries(2)
|
||||
.entrySize(100)
|
||||
.instance().replicatedViaChannel(hubA.createChannel((short) 1)).create();
|
||||
}
|
||||
|
||||
@@ -72,7 +72,8 @@ public class ChannelReplicationTest {
|
||||
.createWithId((byte) 2);
|
||||
|
||||
map1b = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.entries(1000)
|
||||
.entries(2)
|
||||
.entrySize(100)
|
||||
.instance().replicatedViaChannel(hubB.createChannel((short) 1)).create();
|
||||
}
|
||||
}
|
||||
@@ -90,17 +91,18 @@ public class ChannelReplicationTest {
|
||||
}
|
||||
|
||||
|
||||
@Ignore
|
||||
|
||||
@Test
|
||||
public void test() throws IOException, InterruptedException {
|
||||
|
||||
map2b = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.entries(1000)
|
||||
.entries(2)
|
||||
.entrySize(100)
|
||||
.instance().replicatedViaChannel(hubB.createChannel((short) 2)).create();
|
||||
|
||||
|
||||
map2a = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.entries(1000)
|
||||
.entries(2)
|
||||
.entrySize(100)
|
||||
.instance().replicatedViaChannel(hubA.createChannel((short) 2)).create();
|
||||
|
||||
map2a.put(1, "EXAMPLE-2");
|
||||
|
||||
Reference in New Issue
Block a user