use of com.questdb.net.ha.config.ServerNode in project questdb by bluestreak01.
the class ServerNodeTest method testHostAndPort.
@Test
public void testHostAndPort() {
ServerNode node = new ServerNode(0, "github.questdb.org:8080");
Assert.assertEquals("github.questdb.org", node.getHostname());
Assert.assertEquals(8080, node.getPort());
}
use of com.questdb.net.ha.config.ServerNode in project questdb by bluestreak01.
the class ServerNodeTest method testIPv6AndPort.
@Test
public void testIPv6AndPort() {
ServerNode node = new ServerNode(0, "[fe80::5fc:43c:eef0:5b8e%3]:7090");
Assert.assertEquals("fe80::5fc:43c:eef0:5b8e%3", node.getHostname());
Assert.assertEquals(7090, node.getPort());
}
use of com.questdb.net.ha.config.ServerNode in project questdb by bluestreak01.
the class ClusteredProducerMain method main.
public static void main(String[] args) throws JournalException, IOException, JournalNetworkException, NumericException {
final String pathToDatabase = args[0];
final int instance = Numbers.parseInt(args[1]);
final JournalConfiguration configuration = new JournalConfigurationBuilder() {
{
$(Price.class).$ts();
}
}.build(pathToDatabase);
final Factory factory = new Factory(configuration, 1000, 1, 0);
final JournalWriter<Price> writer = factory.writer(new JournalKey<>(Price.class, null, PartitionBy.DEFAULT, 1000000000));
final WorkerController wc = new WorkerController(writer);
final ClusterController cc = new ClusterController(new ServerConfig() {
{
addNode(new ServerNode(1, "127.0.0.1:7080"));
addNode(new ServerNode(2, "127.0.0.1:7090"));
}
}, new ClientConfig(), factory, instance, new ArrayList<JournalWriter>() {
{
add(writer);
}
}, wc);
cc.start();
Runtime.getRuntime().addShutdownHook(new Thread(cc::halt));
}
use of com.questdb.net.ha.config.ServerNode in project questdb by bluestreak01.
the class ClusterControllerTest method testBusyFailOver.
@Test
@Ignore
public void testBusyFailOver() throws Exception {
try (JournalWriter<Quote> writer1 = getFactory().writer(Quote.class)) {
try (final JournalWriter<Quote> writer2 = tf.getFactory().writer(Quote.class)) {
final CountDownLatch active1 = new CountDownLatch(1);
final CountDownLatch active2 = new CountDownLatch(1);
final CountDownLatch standby2 = new CountDownLatch(1);
final AtomicLong expected = new AtomicLong();
final AtomicLong actual = new AtomicLong();
ClusterController controller1 = new ClusterController(new ServerConfig() {
{
addNode(new ServerNode(0, "localhost:7080"));
addNode(new ServerNode(1, "localhost:7090"));
setEnableMultiCast(false);
setHeartbeatFrequency(50);
}
}, new ClientConfig() {
{
setEnableMultiCast(false);
}
}, getFactory(), 0, new ArrayList<JournalWriter>() {
{
add(writer1);
}
}, new ClusterStatusListener() {
@Override
public void goActive() {
try {
TestUtils.generateQuoteData(writer1, 100000);
TestUtils.generateQuoteData(writer1, 100000, writer1.getMaxTimestamp());
writer1.commit();
TestUtils.generateQuoteData(writer1, 100000, writer1.getMaxTimestamp());
writer1.commit();
TestUtils.generateQuoteData(writer1, 100000, writer1.getMaxTimestamp());
writer1.commit();
TestUtils.generateQuoteData(writer1, 100000, writer1.getMaxTimestamp());
writer1.commit();
expected.set(writer1.size());
active1.countDown();
} catch (JournalException | NumericException e) {
e.printStackTrace();
}
}
@Override
public void goPassive(ServerNode activeNode) {
}
@Override
public void onShutdown() {
}
});
ClusterController controller2 = new ClusterController(new ServerConfig() {
{
addNode(new ServerNode(0, "localhost:7080"));
addNode(new ServerNode(1, "localhost:7090"));
setEnableMultiCast(false);
setHeartbeatFrequency(50);
}
}, new ClientConfig() {
{
setEnableMultiCast(false);
}
}, tf.getFactory(), 1, new ArrayList<JournalWriter>() {
{
add(writer2);
}
}, new ClusterStatusListener() {
@Override
public void goActive() {
try {
actual.set(writer2.size());
active2.countDown();
} catch (JournalException e) {
e.printStackTrace();
}
}
@Override
public void goPassive(ServerNode activeNode) {
standby2.countDown();
}
@Override
public void onShutdown() {
}
});
controller1.start();
Assert.assertTrue(active1.await(30, TimeUnit.SECONDS));
Assert.assertEquals(0, active1.getCount());
controller2.start();
standby2.await(60, TimeUnit.SECONDS);
Assert.assertEquals(0, standby2.getCount());
controller1.halt();
active2.await(10, TimeUnit.SECONDS);
Assert.assertEquals(0, active2.getCount());
controller2.halt();
Assert.assertTrue(expected.get() > 0);
Assert.assertEquals(expected.get(), actual.get());
}
}
}
use of com.questdb.net.ha.config.ServerNode in project questdb by bluestreak01.
the class DataLossTest method testDiscardFile.
@Test
@Ignore
public void testDiscardFile() throws Exception {
// create master journal
try (JournalWriter<Quote> master = getFactory().writer(Quote.class, "master")) {
TestUtils.generateQuoteData(master, 300, master.getMaxTimestamp());
master.commit();
// publish master out
JournalServer server = new JournalServer(new ServerConfig() {
{
addNode(new ServerNode(0, "localhost"));
setEnableMultiCast(false);
setHeartbeatFrequency(50);
}
}, getFactory());
server.publish(master);
server.start();
final AtomicInteger counter = new AtomicInteger();
final AtomicInteger doNotExpect = new AtomicInteger();
// equalize slave
JournalClient client = new JournalClient(new ClientConfig("localhost") {
{
setEnableMultiCast(false);
}
}, getFactory());
client.subscribe(Quote.class, "master", "slave", new JournalListener() {
@Override
public void onCommit() {
counter.incrementAndGet();
}
@Override
public void onEvent(int event) {
}
});
client.start();
TestUtils.assertCounter(counter, 1, 10, TimeUnit.SECONDS);
// stop client to be able to add to slave manually
client.halt();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
// add more data to slave
try (JournalWriter<Quote> slave = getFactory().writer(Quote.class, "slave")) {
TestUtils.generateQuoteData(slave, 200, slave.getMaxTimestamp());
slave.commit();
}
// synchronise slave again
client = new JournalClient(new ClientConfig("localhost"), getFactory());
client.subscribe(Quote.class, "master", "slave", new JournalListener() {
@Override
public void onCommit() {
doNotExpect.incrementAndGet();
}
@Override
public void onEvent(int event) {
counter.incrementAndGet();
}
});
client.start();
TestUtils.assertCounter(counter, 2, 180, TimeUnit.SECONDS);
client.halt();
Assert.assertEquals(0, doNotExpect.get());
try (JournalWriter w = getFactory().writer(Quote.class, "slave")) {
Assert.assertNotNull(w);
}
server.halt();
}
}
Aggregations