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());
}
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);
}
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);
}
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());
}
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());
}
Aggregations