Search in sources :

Example 51 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class JournalServerAgentTest method testJournalIndexCorrectness.

@Test
public void testJournalIndexCorrectness() throws Exception {
    server.publish(tradeWriter);
    server.start();
    try (Journal<Quote> quoteClientWriter = getFactory().writer(Quote.class, "client")) {
        // send quote journal key
        // commandProducer.write(channel, Command.ADD_KEY_CMD);
        // setKeyRequestProducer.write(channel, new IndexedJournalKey(3, quoteWriter.getKey()));
        // agent.process(channel);
        // charSequenceResponseConsumer.reset();
        // charSequenceResponseConsumer.read(channel);
        // Assert.assertTrue(charSequenceResponseConsumer.isComplete());
        // Assert.assertEquals("Journal index is too large. Max 1", charSequenceResponseConsumer.getValue());
        commandProducer.write(channel, Command.ADD_KEY_CMD);
        setKeyRequestProducer.write(channel, new IndexedJournalKey(0, quoteWriter.getMetadata().getKey()));
        agent.process(channel);
        charSequenceResponseConsumer.read(channel);
        TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue());
        hugeBufferConsumer.read(channel);
        commandProducer.write(channel, Command.DELTA_REQUEST_CMD);
        journalClientStateProducer.write(channel, new IndexedJournal(1, quoteClientWriter));
        agent.process(channel);
        charSequenceResponseConsumer.read(channel);
        TestUtils.assertEquals("Journal index does not match key request", charSequenceResponseConsumer.getValue());
        commandProducer.write(channel, Command.DELTA_REQUEST_CMD);
        journalClientStateProducer.write(channel, new IndexedJournal(0, quoteClientWriter));
        agent.process(channel);
        charSequenceResponseConsumer.read(channel);
        TestUtils.assertEquals("OK", charSequenceResponseConsumer.getValue());
    }
}
Also used : Quote(com.questdb.model.Quote) IndexedJournalKey(com.questdb.net.ha.model.IndexedJournalKey) IndexedJournal(com.questdb.net.ha.model.IndexedJournal) AbstractTest(com.questdb.test.tools.AbstractTest)

Example 52 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class JournalSymbolTableTest method setUp.

@Before
public void setUp() throws Exception {
    origin = getFactory().writer(Quote.class, "origin");
    master = getFactory().writer(Quote.class, "master");
    slave = getFactory().writer(Quote.class, "slave");
    channel = new MockByteChannel();
    journalSymbolTableProducer = new JournalSymbolTableProducer(master);
    journalSymbolTableConsumer = new JournalSymbolTableConsumer(slave);
    origin.append(new Quote().setSym("AB").setEx("EX1").setMode("M1"));
    origin.append(new Quote().setSym("CD").setEx("EX2").setMode("M2"));
    origin.append(new Quote().setSym("EF").setEx("EX3").setMode("M2"));
    origin.append(new Quote().setSym("GH").setEx("EX3").setMode("M3"));
}
Also used : Quote(com.questdb.model.Quote) JournalSymbolTableProducer(com.questdb.net.ha.producer.JournalSymbolTableProducer) JournalSymbolTableConsumer(com.questdb.net.ha.comsumer.JournalSymbolTableConsumer) Before(org.junit.Before)

Example 53 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class SSLTest method testAuthBothCertsMissing.

@Test
@Ignore
public void testAuthBothCertsMissing() throws Exception {
    try (JournalWriter<Quote> remote = getFactory().writer(Quote.class, "remote")) {
        JournalServer server = new JournalServer(new ServerConfig() {

            {
                setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500));
                getSslConfig().setSecure(true);
                getSslConfig().setRequireClientAuth(true);
                try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
                    getSslConfig().setKeyStore(is, "changeit");
                }
                setEnableMultiCast(false);
                setHeartbeatFrequency(50);
            }
        }, getFactory());
        try {
            final AtomicInteger serverErrorCount = new AtomicInteger();
            final CountDownLatch terminated = new CountDownLatch(1);
            JournalClient client = new JournalClient(new ClientConfig("localhost") {

                {
                    getSslConfig().setSecure(true);
                    try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
                        getSslConfig().setTrustStore(is, "changeit");
                    }
                }
            }, getFactory(), null, evt -> {
                switch(evt) {
                    case JournalClientEvents.EVT_SERVER_ERROR:
                        serverErrorCount.incrementAndGet();
                        break;
                    case JournalClientEvents.EVT_TERMINATED:
                        terminated.countDown();
                        break;
                    default:
                        break;
                }
            });
            server.publish(remote);
            server.start();
            client.subscribe(Quote.class, "remote", "local");
            client.start();
            Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS));
            Assert.assertEquals(0, server.getConnectedClients());
            Assert.assertFalse(client.isRunning());
            Assert.assertEquals(1, serverErrorCount.get());
        } finally {
            server.halt();
        }
    }
}
Also used : Quote(com.questdb.model.Quote) ServerConfig(com.questdb.net.ha.config.ServerConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputStream(java.io.InputStream) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConfig(com.questdb.net.ha.config.ClientConfig)

Example 54 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class SSLTest method testNonAuthClientTrustMissing.

@Test
public void testNonAuthClientTrustMissing() throws Exception {
    try (JournalWriter<Quote> remote = getFactory().writer(Quote.class, "remote")) {
        JournalServer server = new JournalServer(new ServerConfig() {

            {
                setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500));
                getSslConfig().setSecure(true);
                try (InputStream is = this.getClass().getResourceAsStream("/keystore/singlekey.ks")) {
                    getSslConfig().setKeyStore(is, "changeit");
                }
                setEnableMultiCast(false);
                setHeartbeatFrequency(50);
            }
        }, getFactory());
        try {
            final AtomicInteger serverErrorCount = new AtomicInteger();
            final CountDownLatch terminated = new CountDownLatch(1);
            JournalClient client = new JournalClient(new ClientConfig("localhost") {

                {
                    getSslConfig().setSecure(true);
                }
            }, getFactory(), null, evt -> {
                switch(evt) {
                    case JournalClientEvents.EVT_SERVER_ERROR:
                        serverErrorCount.incrementAndGet();
                        break;
                    case JournalClientEvents.EVT_TERMINATED:
                        terminated.countDown();
                        break;
                    default:
                        break;
                }
            });
            server.publish(remote);
            server.start();
            client.subscribe(Quote.class, "remote", "local");
            client.subscribe(Quote.class, "remote", "local");
            client.start();
            Assert.assertTrue(terminated.await(5, TimeUnit.SECONDS));
            // Assert.assertEquals(0, server.getConnectedClients());
            Assert.assertFalse(client.isRunning());
            Assert.assertEquals(1, serverErrorCount.get());
            client.halt();
        } finally {
            server.halt();
        }
    }
}
Also used : Quote(com.questdb.model.Quote) ServerConfig(com.questdb.net.ha.config.ServerConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputStream(java.io.InputStream) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConfig(com.questdb.net.ha.config.ClientConfig)

Example 55 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class PrinterTest method testDateConversion.

@Test
public void testDateConversion() throws Exception {
    long millis = DateFormatUtils.parseDateTime("2013-10-11T10:00:00.000Z");
    Quote position1 = new Quote().setBidSize(10).setTimestamp(millis);
    Quote position2 = new Quote().setTimestamp(millis);
    try (JournalPrinter printer = new JournalPrinter()) {
        printer.types(Quote.class, int.class);
        printer.setAppender(testAppender);
        printer.f("timestamp").i(0).h("TimeStamp").c(new DateConverter(printer)).f("bidSize").f("askSize").v(1).h("test");
        printer.header();
        printer.out(position1, 0);
        printer.out(position2, 1);
        testAppender.assertLine("TimeStamp\tbidSize\taskSize\ttest", 0);
        testAppender.assertLine("2013-10-11T10:00:00.000Z\t10\t0\t0", 1);
        testAppender.assertLine("2013-10-11T10:00:00.000Z\t0\t0\t1", 2);
    }
}
Also used : Quote(com.questdb.model.Quote) DateConverter(com.questdb.printer.converter.DateConverter) Test(org.junit.Test)

Aggregations

Quote (com.questdb.model.Quote)80 Test (org.junit.Test)64 AbstractTest (com.questdb.test.tools.AbstractTest)63 ClientConfig (com.questdb.net.ha.config.ClientConfig)20 CountDownLatch (java.util.concurrent.CountDownLatch)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 JournalException (com.questdb.std.ex.JournalException)11 ServerConfig (com.questdb.net.ha.config.ServerConfig)10 ArrayList (java.util.ArrayList)9 Interval (com.questdb.std.time.Interval)8 InputStream (java.io.InputStream)6 JournalConfigurationBuilder (com.questdb.store.factory.configuration.JournalConfigurationBuilder)5 File (java.io.File)5 JournalListener (com.questdb.store.JournalListener)4 ServerNode (com.questdb.net.ha.config.ServerNode)3 RecordSource (com.questdb.ql.RecordSource)3 Rnd (com.questdb.std.Rnd)3 StringSink (com.questdb.std.str.StringSink)3 Ignore (org.junit.Ignore)3 NumericException (com.questdb.common.NumericException)2