Made TcpConfig back immutable; Draw the borderline: Builders are mutable, Configs are immutable (hence ChronicleHashInstanceBuilder and StatelessClientBuilder renamed to Configs; improved TcpConfig static factory naming

This commit is contained in:
leventov
2014-11-07 12:24:52 +03:00
parent 4a51b129a3
commit 4c86dae04f
29 changed files with 198 additions and 215 deletions
@@ -25,6 +25,7 @@ import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
/**
@@ -71,7 +72,7 @@ public class Builder {
final byte identifier,
final int serverPort,
final InetSocketAddress... endpoints) throws IOException {
TcpConfig tcpConfig = TcpConfig.of(serverPort, endpoints)
TcpConfig tcpConfig = TcpConfig.unknownTopology(serverPort, Arrays.asList(endpoints))
.heartBeatInterval(1L, TimeUnit.SECONDS);
return ChronicleMapBuilder.of(kClass, vClass)
.replication(identifier, tcpConfig);
@@ -54,7 +54,7 @@ public class ChannelReplicationTest {
public void setup() throws IOException {
{
TcpConfig tcpConfig = TcpConfig
.of(8086, new InetSocketAddress("localhost", 8087))
.forSendingNode(8086, new InetSocketAddress("localhost", 8087))
.heartBeatInterval(1, SECONDS);
hubA = ReplicationHub.builder()
@@ -68,7 +68,7 @@ public class ChannelReplicationTest {
{
TcpConfig tcpConfig =
TcpConfig.of(8087).heartBeatInterval(1, SECONDS);
TcpConfig.forReceivingOnlyNode(8087).heartBeatInterval(1, SECONDS);
hubB = ReplicationHub.builder().tcpTransportAndNetwork(tcpConfig)
.create((byte) 2);
@@ -30,6 +30,8 @@ import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import static net.openhft.chronicle.hash.replication.TcpConfig.forSendingNode;
/**
* Test ReplicatedChronicleMap where the Replicated is over a TCP Socket
*
@@ -85,7 +87,7 @@ public class EventListenerTestWithTCPSocketReplication {
// we connect the maps via a TCP socket connection on port 8077
TcpConfig tcpConfig = TcpConfig.of(8076, new InetSocketAddress("localhost", 8077));
TcpConfig tcpConfig = forSendingNode(8076, new InetSocketAddress("localhost", 8077));
ChronicleMapBuilder<Integer, CharSequence> map1Builder =
ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
@@ -96,7 +98,7 @@ public class EventListenerTestWithTCPSocketReplication {
// ---------- SERVER2 2 on the same server as ----------
{
TcpConfig tcpConfig = TcpConfig.of(8077);
TcpConfig tcpConfig = TcpConfig.forReceivingOnlyNode(8077);
ChronicleMapBuilder<Integer, CharSequence> map2Builder =
ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
@@ -158,7 +160,7 @@ public class EventListenerTestWithTCPSocketReplication {
// we connect the maps via a TCP socket connection on port 8077
TcpConfig tcpConfig = TcpConfig.of(8076, new InetSocketAddress("localhost", 8077));
TcpConfig tcpConfig = forSendingNode(8076, new InetSocketAddress("localhost", 8077));
ChronicleMapBuilder<Integer, CharSequence> map1Builder =
ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
@@ -170,7 +172,7 @@ public class EventListenerTestWithTCPSocketReplication {
// ---------- SERVER2 2 on the same server as ----------
{
TcpConfig tcpConfig = TcpConfig.of(8077);
TcpConfig tcpConfig = TcpConfig.forReceivingOnlyNode(8077);
ChronicleMapBuilder<Integer, CharSequence> map2Builder =
ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
@@ -233,7 +235,7 @@ public class EventListenerTestWithTCPSocketReplication {
// we connect the maps via a TCP socket connection on port 8077
TcpConfig tcpConfig = TcpConfig.of(8076, new InetSocketAddress("localhost", 8077));
TcpConfig tcpConfig = forSendingNode(8076, new InetSocketAddress("localhost", 8077));
ChronicleMapBuilder<Integer, CharSequence> map1Builder =
ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
@@ -245,7 +247,7 @@ public class EventListenerTestWithTCPSocketReplication {
// ---------- SERVER2 2 on the same server as ----------
{
TcpConfig tcpConfig = TcpConfig.of(8077);
TcpConfig tcpConfig = TcpConfig.forReceivingOnlyNode(8077);
ChronicleMapBuilder<Integer, CharSequence> map2Builder =
ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
@@ -63,7 +63,7 @@ public class PostChannelCreationTest {
{
final TcpConfig tcpConfig = TcpConfig
.of(8086, new InetSocketAddress("localhost", 8087))
.forSendingNode(8086, new InetSocketAddress("localhost", 8087))
.heartBeatInterval(1, SECONDS);
hubA = ReplicationHub.builder().tcpTransportAndNetwork(tcpConfig)
@@ -82,7 +82,7 @@ public class PostChannelCreationTest {
{
final TcpConfig tcpConfig = TcpConfig
.of(8087, new InetSocketAddress("localhost", 8086))
.forSendingNode(8087, new InetSocketAddress("localhost", 8086))
.heartBeatInterval(1, SECONDS);
hubB = ReplicationHub.builder().tcpTransportAndNetwork(tcpConfig)
@@ -61,7 +61,7 @@ public class SingleMapChannelTest {
{
final TcpConfig tcpConfig = TcpConfig
.of(8086, new InetSocketAddress("localhost", 8087))
.forSendingNode(8086, new InetSocketAddress("localhost", 8087))
.heartBeatInterval(1, SECONDS);
int maxEntrySize = 1024;
byte identifier= 1;
@@ -78,7 +78,7 @@ public class SingleMapChannelTest {
{
final TcpConfig tcpConfig = TcpConfig
.of(8087, new InetSocketAddress("localhost", 8086))
.forSendingNode(8087, new InetSocketAddress("localhost", 8086))
.heartBeatInterval(1, SECONDS);
hubB = ReplicationHub.builder().tcpTransportAndNetwork(tcpConfig).create((byte) 2);
@@ -56,7 +56,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
}
@@ -99,7 +99,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
}
@@ -140,7 +140,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
}
@@ -173,7 +173,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
serverMap.put(10, "EXAMPLE-10");
}
@@ -212,7 +212,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
serverMap.put(10, "EXAMPLE-10");
}
@@ -244,7 +244,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
}
@@ -287,7 +287,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086))
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086))
.putReturnsNull(true)
.create();
}
@@ -333,7 +333,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086))
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086))
.putReturnsNull(true)
.removeReturnsNull(true)
.create();
@@ -372,7 +372,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086))
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086))
.putReturnsNull(true)
.removeReturnsNull(true)
.create();
@@ -415,9 +415,9 @@ public class StatelessClientTest {
// server
{
serverMap1 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
serverMap2 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8077)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8077)).create();
}
@@ -26,6 +26,7 @@ import org.junit.Test;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -47,7 +48,7 @@ public class TCPSocketReplicationTest3wayPutReturnsNull {
final byte identifier,
final int serverPort,
final InetSocketAddress... endpoints) throws IOException {
TcpConfig tcpConfig = TcpConfig.of(serverPort, endpoints);
TcpConfig tcpConfig = TcpConfig.unknownTopology(serverPort, Arrays.asList(endpoints));
return (T) ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.putReturnsNull(true)
@@ -30,7 +30,6 @@ import java.net.InetSocketAddress;
import static java.util.concurrent.TimeUnit.SECONDS;
import static net.openhft.chronicle.map.Builder.getPersistenceFile;
import static net.openhft.chronicle.hash.replication.TcpConfig.of;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -47,7 +46,7 @@ public class TwoMapOnDifferentServers {
public void setup() throws IOException {
final TcpConfig tcpConfig =
of(8076, new InetSocketAddress("localhost", 8077))
TcpConfig.forSendingNode(8076, new InetSocketAddress("localhost", 8077))
.heartBeatInterval(1, SECONDS);
@@ -57,7 +56,8 @@ public class TwoMapOnDifferentServers {
map2 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000)
.replication((byte) 2, of(8077).heartBeatInterval(1, SECONDS)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8077)
.heartBeatInterval(1, SECONDS)).create();
}
@After
@@ -70,7 +70,7 @@ public class ChannelExample {
byte identifier = (byte) 1;
TcpConfig tcpConfig = TcpConfig
.of(8086, new InetSocketAddress("localhost", 8087))
.forSendingNode(8086, new InetSocketAddress("localhost", 8087))
.heartBeatInterval(1, SECONDS);
@@ -105,7 +105,7 @@ public class ChannelExample {
byte identifier = (byte) 2;
TcpConfig tcpConfig =
TcpConfig.of(8087).heartBeatInterval(1, SECONDS);
TcpConfig.forReceivingOnlyNode(8087).heartBeatInterval(1, SECONDS);
hubOnServer2 = ReplicationHub.builder()
.tcpTransportAndNetwork(tcpConfig)
@@ -192,7 +192,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
final ChronicleMap<Integer, String> serverMap =
ChronicleMapBuilder.of(Integer.class, String.class)
.replication((byte) 1, TcpConfig.of(port)).create();
.replication((byte) 1, TcpConfig.forReceivingOnlyNode(port)).create();
final ChronicleMap<Integer, String> statelessMap = ChronicleMapBuilder.of(Integer
.class, String.class)
@@ -206,7 +206,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
IOException {
final ChronicleMap<CharSequence, CharSequence> serverMap = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(port)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(port)).create();
final ChronicleMap<CharSequence, CharSequence> statelessMap = ChronicleMapBuilder.of(CharSequence
@@ -18,6 +18,7 @@
package net.openhft.chronicle.set;
import net.openhft.chronicle.hash.replication.TcpConfig;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -25,10 +26,11 @@ import org.junit.Test;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Arrays;
import static java.util.Arrays.asList;
import static java.util.concurrent.TimeUnit.SECONDS;
import static net.openhft.chronicle.map.Builder.getPersistenceFile;
import static net.openhft.chronicle.hash.replication.TcpConfig.of;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -51,7 +53,7 @@ public class SetForTCPSocketReplicationTest3way {
final int serverPort,
final InetSocketAddress... endpoints) throws IOException {
return (T) ChronicleSetBuilder.of(Integer.class)
.replication(identifier, of(serverPort, endpoints)
.replication(identifier, TcpConfig.unknownTopology(serverPort, asList(endpoints))
.heartBeatInterval(1L, SECONDS))
.createPersistedTo(getPersistenceFile());
}