@Test public void testJsonConversionWithoutOptionalProperties() throws Exception { final ReplicationConfig defaultCfg = Jackson.readValue( '{' + " \"method\": \"ZOOKEEPER\"," + " \"serverId\": 10," + " \"servers\": {" + " \"10\": {" + " \"host\": \"foo\"," + " \"quorumPort\": 100," + " \"electionPort\": 101" + " }," + " \"11\": {" + " \"host\": \"bar\"," + " \"quorumPort\": 200," + " \"electionPort\": 201" + " }" + " }" + '}', ReplicationConfig.class); assertThat(defaultCfg).isEqualTo( new ZooKeeperReplicationConfig( 10, ImmutableMap.of(10, new ZooKeeperAddress("foo", 100, 101, 0), 11, new ZooKeeperAddress("bar", 200, 201, 0)), null, null, null, null, null, null)); }
@Test public void testJsonConversion() throws Exception { final ZooKeeperReplicationConfig cfg = new ZooKeeperReplicationConfig( 1, ImmutableMap.of(1, new ZooKeeperAddress("2", 3, 4, 5), 6, new ZooKeeperAddress("7", 8, 9, 10)),
@Override protected void configure(CentralDogmaBuilder builder) { // Set up a cluster of two replicas where the second replica is always unavailable, final int quorumPort = InstanceSpec.getRandomPort(); final int electionPort = InstanceSpec.getRandomPort(); final int clientPort = InstanceSpec.getRandomPort(); builder.replication(new ZooKeeperReplicationConfig( 1, ImmutableMap.of(1, new ZooKeeperAddress("127.0.0.1", quorumPort, electionPort, clientPort), 2, new ZooKeeperAddress("127.0.0.1", 1, 1, 1)))); } };
Replica(InstanceSpec spec, Map<Integer, ZooKeeperAddress> servers, Function<Command<?>, CompletableFuture<?>> delegate, boolean start) throws Exception { this.delegate = delegate; dataDir = spec.getDataDirectory(); final int id = spec.getServerId(); final ZooKeeperReplicationConfig zkCfg = new ZooKeeperReplicationConfig(id, servers); rm = new ZooKeeperCommandExecutor(zkCfg, dataDir, new AbstractCommandExecutor(null, null) { @Override public int replicaId() { return id; } @Override protected void doStart(@Nullable Runnable onTakeLeadership, @Nullable Runnable onReleaseLeadership) {} @Override protected void doStop(@Nullable Runnable onReleaseLeadership) {} @Override @SuppressWarnings("unchecked") protected <T> CompletableFuture<T> doExecute(Command<T> command) { return (CompletableFuture<T>) delegate.apply(command); } }, null, null); startFuture = start ? rm.start() : null; }
.mirroringEnabled(false) .gracefulShutdownTimeout(new GracefulShutdownTimeout(0, 0)) .replication(new ZooKeeperReplicationConfig(1, servers)) .build(); .mirroringEnabled(false) .gracefulShutdownTimeout(new GracefulShutdownTimeout(0, 0)) .replication(new ZooKeeperReplicationConfig(2, servers)) .build();