Search in sources :

Example 6 with NativeLPSZ

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

the class NetTest method testSeek.

@Test
public void testSeek() {
    int port = 9993;
    NativeLPSZ lpsz = new NativeLPSZ();
    String msg = "Test ABC";
    CharSequenceZ charSink = new CharSequenceZ(msg);
    int msgLen = charSink.length() + 1;
    long acceptFd = Net.socketTcp(true);
    Assert.assertTrue(acceptFd > 0);
    Assert.assertTrue(Net.bindTcp(acceptFd, 0, port));
    Net.listen(acceptFd, 1024);
    long clientFd = Net.socketTcp(true);
    long sockAddr = Net.sockaddr("127.0.0.1", port);
    TestUtils.assertConnect(clientFd, sockAddr);
    Assert.assertEquals(msgLen, Net.send(clientFd, charSink.address(), msgLen));
    Net.close(clientFd);
    Net.freeSockAddr(sockAddr);
    long serverFd = Net.accept(acceptFd);
    long serverBuf = Unsafe.malloc(msgLen, MemoryTag.NATIVE_DEFAULT);
    Assert.assertEquals(msgLen, Net.peek(serverFd, serverBuf, msgLen));
    lpsz.of(serverBuf);
    Assert.assertEquals(msg, lpsz.toString());
    Assert.assertEquals(msgLen, Net.recv(serverFd, serverBuf, msgLen));
    lpsz.of(serverBuf);
    Assert.assertEquals(msg, lpsz.toString());
    Unsafe.free(serverBuf, msgLen, MemoryTag.NATIVE_DEFAULT);
    Net.close(serverFd);
    Net.close(acceptFd);
    charSink.close();
}
Also used : CharSequenceZ(io.questdb.std.str.CharSequenceZ) NativeLPSZ(io.questdb.std.str.NativeLPSZ) Test(org.junit.Test)

Aggregations

NativeLPSZ (io.questdb.std.str.NativeLPSZ)6 Path (io.questdb.std.str.Path)5 Test (org.junit.Test)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 RingQueue (io.questdb.mp.RingQueue)1 SCSequence (io.questdb.mp.SCSequence)1 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)1 SPSequence (io.questdb.mp.SPSequence)1 io.questdb.std (io.questdb.std)1 MicrosecondClock (io.questdb.std.datetime.microtime.MicrosecondClock)1 TimestampFormatUtils (io.questdb.std.datetime.microtime.TimestampFormatUtils)1 CharSequenceZ (io.questdb.std.str.CharSequenceZ)1 TestUtils (io.questdb.test.tools.TestUtils)1 File (java.io.File)1 LockSupport (java.util.concurrent.locks.LockSupport)1 Assert (org.junit.Assert)1 Rule (org.junit.Rule)1 TemporaryFolder (org.junit.rules.TemporaryFolder)1