use of io.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.
the class HttpMultipartContentParserTest method testMalformedAtEnd.
@Test
public void testMalformedAtEnd() throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (HttpMultipartContentParser multipartContentParser = new HttpMultipartContentParser(new HttpHeaderParser(1024, pool))) {
final String content = "------WebKitFormBoundaryxFKYDBybTLu2rb8PA--\r\n";
int len = content.length();
long p = TestUtils.toMemory(content);
try {
String boundary = "\r\n------WebKitFormBoundaryxFKYDBybTLu2rb8P";
long pBoundary = TestUtils.toMemory(boundary);
DirectByteCharSequence boundaryCs = new DirectByteCharSequence().of(pBoundary, pBoundary + boundary.length());
try {
multipartContentParser.of(boundaryCs);
multipartContentParser.parse(p, p + len, LISTENER);
Assert.fail();
} catch (HttpException e) {
TestUtils.assertContains(e.getFlyweightMessage(), "Malformed start boundary");
} finally {
Unsafe.free(pBoundary, boundary.length(), MemoryTag.NATIVE_DEFAULT);
}
} finally {
Unsafe.free(p, len, MemoryTag.NATIVE_DEFAULT);
}
}
});
}
use of io.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.
the class MangledUtf8SinkTest method testEquals.
private void testEquals(String testVal) {
byte[] utf8 = testVal.getBytes(StandardCharsets.UTF_8);
int bufSize = utf8.length;
long buffer = Unsafe.malloc(bufSize, MemoryTag.NATIVE_DEFAULT);
for (int i = 0; i < bufSize; i++) {
Unsafe.getUnsafe().putByte(buffer + i, utf8[i]);
}
DirectByteCharSequence directByteCharSequence = new DirectByteCharSequence();
directByteCharSequence.of(buffer, buffer + bufSize);
Assert.assertEquals(testVal, directByteCharSequence.toString());
CharSequence result = testSink.encodeMangledUtf8(testVal);
TestUtils.assertEquals(directByteCharSequence, result);
Assert.assertEquals(directByteCharSequence.hashCode(), result.hashCode());
// Same after materializing to a string
String stringResult = result.toString();
Assert.assertEquals(directByteCharSequence, result);
Assert.assertEquals(directByteCharSequence.hashCode(), stringResult.hashCode());
}
use of io.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.
the class AssociativeCacheTest method testImmutableKeys.
@Test
public void testImmutableKeys() {
final AssociativeCache<String> cache = new AssociativeCache<>(8, 8);
long mem = Unsafe.malloc(1024, MemoryTag.NATIVE_DEFAULT);
final DirectByteCharSequence dbcs = new DirectByteCharSequence();
try {
Unsafe.getUnsafe().putByte(mem, (byte) 'A');
Unsafe.getUnsafe().putByte(mem + 1, (byte) 'B');
cache.put(dbcs.of(mem, mem + 2), "hello1");
Unsafe.getUnsafe().putByte(mem, (byte) 'C');
Unsafe.getUnsafe().putByte(mem + 1, (byte) 'D');
cache.put(dbcs, "hello2");
Unsafe.getUnsafe().putByte(mem, (byte) 'A');
Unsafe.getUnsafe().putByte(mem + 1, (byte) 'B');
Assert.assertEquals("hello1", cache.peek(dbcs));
Unsafe.getUnsafe().putByte(mem, (byte) 'C');
Unsafe.getUnsafe().putByte(mem + 1, (byte) 'D');
Assert.assertEquals("hello2", cache.peek(dbcs));
} finally {
Unsafe.free(mem, 1024, MemoryTag.NATIVE_DEFAULT);
}
}
Aggregations