Search in sources :

Example 21 with StringSink

use of io.questdb.std.str.StringSink in project questdb by bluestreak01.

the class NetTest method bindAcceptConnectClose.

private void bindAcceptConnectClose() throws InterruptedException, BrokenBarrierException {
    int port = this.port++;
    long fd = Net.socketTcp(true);
    Assert.assertTrue(fd > 0);
    Assert.assertTrue(Net.bindTcp(fd, 0, port));
    Net.listen(fd, 1024);
    // make sure peerIp in correct byte order
    StringSink sink = new StringSink();
    CountDownLatch haltLatch = new CountDownLatch(1);
    CyclicBarrier barrier = new CyclicBarrier(2);
    AtomicBoolean threadFailed = new AtomicBoolean(false);
    new Thread(() -> {
        try {
            barrier.await();
            long clientFd = Net.accept(fd);
            Net.appendIP4(sink, Net.getPeerIP(clientFd));
            Net.configureNoLinger(clientFd);
            Net.close(clientFd);
        } catch (Exception e) {
            threadFailed.set(true);
            e.printStackTrace();
        } finally {
            haltLatch.countDown();
        }
    }).start();
    barrier.await();
    long clientFd = Net.socketTcp(true);
    long sockAddr = Net.sockaddr("127.0.0.1", port);
    long sockFd = -1;
    for (int i = 0; i < 2000; i++) {
        Net.configureNoLinger(clientFd);
        sockFd = Net.connect(clientFd, sockAddr);
        if (sockFd >= 0) {
            break;
        }
        Os.sleep(5);
    }
    Assert.assertEquals(0, sockFd);
    Assert.assertTrue(haltLatch.await(10, TimeUnit.SECONDS));
    Net.close(clientFd);
    Net.close(fd);
    TestUtils.assertEquals("127.0.0.1", sink);
    Assert.assertFalse(threadFailed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StringSink(io.questdb.std.str.StringSink) CountDownLatch(java.util.concurrent.CountDownLatch) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) CyclicBarrier(java.util.concurrent.CyclicBarrier)

Example 22 with StringSink

use of io.questdb.std.str.StringSink in project questdb by bluestreak01.

the class GenericLexerTest method testBlockComments.

@Test
public void testBlockComments() {
    GenericLexer lex = new GenericLexer(64);
    lex.defineSymbol("+");
    lex.defineSymbol("++");
    lex.defineSymbol("*");
    lex.defineSymbol("/*");
    lex.defineSymbol("*/");
    lex.of("a + /* ok, this /* is a */ comment */ 'b' * abc");
    StringSink sink = new StringSink();
    CharSequence token;
    while ((token = SqlUtil.fetchNext(lex)) != null) {
        sink.put(token);
    }
    TestUtils.assertEquals("a+'b'*abc", sink);
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 23 with StringSink

use of io.questdb.std.str.StringSink in project questdb by bluestreak01.

the class GenericLexerTest method testEdgeSymbol.

@Test
public void testEdgeSymbol() {
    GenericLexer ts = new GenericLexer(64);
    ts.defineSymbol(" ");
    ts.defineSymbol("+");
    ts.defineSymbol("(");
    ts.defineSymbol(")");
    ts.defineSymbol(",");
    CharSequence content;
    ts.of(content = "create journal xyz(a int, b int)");
    StringSink sink = new StringSink();
    for (CharSequence cs : ts) {
        sink.put(cs);
    }
    TestUtils.assertEquals(content, sink);
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 24 with StringSink

use of io.questdb.std.str.StringSink in project questdb by bluestreak01.

the class GenericLexerTest method testImmutablePairOf7.

@Test
public void testImmutablePairOf7() {
    GenericLexer ts = new GenericLexer(64);
    String culprit = "geohash 31b";
    ts.of(culprit);
    CharSequence tok0 = GenericLexer.immutableOf(ts.next());
    ts.next();
    CharSequence tok1 = ts.next();
    GenericLexer.FloatingSequencePair pair = (GenericLexer.FloatingSequencePair) ts.immutablePairOf(tok0, tok1);
    Assert.assertEquals(culprit.length() - 1, pair.length());
    StringSink sink = Misc.getThreadLocalBuilder();
    for (int i = 0; i < pair.length(); i++) {
        sink.put(pair.charAt(i));
    }
    pair.clear();
    Assert.assertEquals(pair.toString(), sink.toString());
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 25 with StringSink

use of io.questdb.std.str.StringSink in project questdb by bluestreak01.

the class GenericLexerTest method testImmutablePairOf8.

@Test
public void testImmutablePairOf8() {
    GenericLexer lex = new GenericLexer(64);
    lex.defineSymbol("/");
    String culprit = "#sp052w92p1p8/7";
    lex.of(culprit);
    CharSequence geohashTok = GenericLexer.immutableOf(lex.next());
    // slash
    lex.next();
    CharSequence bitsTok = lex.next();
    GenericLexer.FloatingSequencePair pair = (GenericLexer.FloatingSequencePair) lex.immutablePairOf(geohashTok, '/', bitsTok);
    Assert.assertEquals(culprit, pair.toString());
    StringSink sink = Misc.getThreadLocalBuilder();
    for (int i = 0; i < pair.length(); i++) {
        sink.put(pair.charAt(i));
    }
    pair.clear();
    Assert.assertEquals(pair.toString(), sink.toString());
}
Also used : StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Aggregations

StringSink (io.questdb.std.str.StringSink)284 Test (org.junit.Test)167 Function (io.questdb.cairo.sql.Function)38 BaseConnection (org.postgresql.core.BaseConnection)36 UnaryFunction (io.questdb.griffin.engine.functions.UnaryFunction)28 StrConstant (io.questdb.griffin.engine.functions.constants.StrConstant)22 StrFunction (io.questdb.griffin.engine.functions.StrFunction)20 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)16 Path (io.questdb.std.str.Path)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 CyclicBarrier (java.util.concurrent.CyclicBarrier)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 SqlCompiler (io.questdb.griffin.SqlCompiler)10 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)10 SqlException (io.questdb.griffin.SqlException)9 Metrics (io.questdb.Metrics)8 io.questdb.cairo (io.questdb.cairo)8 AllowAllCairoSecurityContext (io.questdb.cairo.security.AllowAllCairoSecurityContext)8 NetUtils (io.questdb.cutlass.NetUtils)8