use of com.questdb.std.ex.FatalError in project questdb by bluestreak01.
the class Os method loadLib.
private static void loadLib(String lib) {
InputStream is = Os.class.getResourceAsStream(lib);
if (is == null) {
throw new FatalError("Internal error: cannot find " + lib + ", broken package?");
}
try {
File tempLib = null;
try {
int dot = lib.indexOf('.');
tempLib = File.createTempFile(lib.substring(0, dot), lib.substring(dot));
// copy to tempLib
try (FileOutputStream out = new FileOutputStream(tempLib)) {
byte[] buf = new byte[4096];
while (true) {
int read = is.read(buf);
if (read == -1) {
break;
}
out.write(buf, 0, read);
}
} finally {
tempLib.deleteOnExit();
}
System.load(tempLib.getAbsolutePath());
} catch (IOException e) {
throw new FatalError("Internal error: cannot unpack " + tempLib, e);
}
} finally {
Misc.free(is);
}
}
use of com.questdb.std.ex.FatalError in project questdb by bluestreak01.
the class ZipTest method testGzip.
@Test
public void testGzip() throws Exception {
try (Path path = new Path()) {
File outFile = temp.newFile("x");
File expected = new File(ZipTest.class.getResource("/large.csv").getFile());
final int available = 64 * 1024;
long in = Unsafe.malloc(available);
long out = Unsafe.malloc(available / 2);
try {
long strm = Zip.deflateInit();
try {
long pIn = 0;
long pOut = 0;
long fdIn = Files.openRO(path.of(expected.getAbsolutePath()).$());
try {
long fdOut = Files.openRW(path.of(outFile.getAbsolutePath()).$());
try {
// header
Files.write(fdOut, Zip.gzipHeader, Zip.gzipHeaderLen, pOut);
pOut += Zip.gzipHeaderLen;
int len;
int crc = 0;
while ((len = (int) Files.read(fdIn, in, available, pIn)) > 0) {
pIn += len;
Zip.setInput(strm, in, len);
crc = Zip.crc32(crc, in, len);
do {
int ret;
if ((ret = Zip.deflate(strm, out, available, false)) < 0) {
throw new FatalError("Error in deflator: " + ret);
}
int have = available - Zip.availOut(strm);
if (have > 0) {
Files.write(fdOut, out, have, pOut);
pOut += have;
}
} while (Zip.availIn(strm) > 0);
}
int ret;
do {
if ((ret = Zip.deflate(strm, out, available, true)) < 0) {
throw new FatalError("Error in deflator: " + ret);
}
int have = available - Zip.availOut(strm);
if (have > 0) {
Files.write(fdOut, out, have, pOut);
pOut += have;
}
} while (ret != 1);
// write trailer
Unsafe.getUnsafe().putInt(out, crc);
Unsafe.getUnsafe().putInt(out + 4, (int) pIn);
Files.write(fdOut, out, 8, pOut);
} finally {
Files.close(fdOut);
}
} finally {
Files.close(fdIn);
}
} finally {
Zip.deflateEnd(strm);
}
} finally {
Unsafe.free(in, available);
Unsafe.free(out, available / 2);
}
// ok. read what we produced
File actual = temp.newFile();
try (GZIPInputStream is = new GZIPInputStream(new FileInputStream(outFile));
FileOutputStream fos = new FileOutputStream(actual)) {
byte[] buf = new byte[16 * 1024];
int l;
while ((l = is.read(buf)) > 0) {
fos.write(buf, 0, l);
}
}
TestUtils.assertEquals(expected, actual);
}
}
use of com.questdb.std.ex.FatalError in project questdb by bluestreak01.
the class AuthorizationTest method testServerAuthException.
@Test
public void testServerAuthException() throws Exception {
JournalServer server = new JournalServer(new ServerConfig() {
{
setHeartbeatFrequency(TimeUnit.MILLISECONDS.toMillis(500));
setEnableMultiCast(false);
}
}, getFactory(), (token, requestedKeys) -> {
throw new FatalError("BANG!");
});
final AtomicInteger authErrorCount = new AtomicInteger();
final CountDownLatch serverError = new CountDownLatch(1);
JournalClient client = new JournalClient(local, getFactory(), "SECRET"::getBytes, evt -> {
switch(evt) {
case JournalClientEvents.EVT_AUTH_ERROR:
authErrorCount.incrementAndGet();
break;
case JournalClientEvents.EVT_TERMINATED:
serverError.countDown();
break;
default:
break;
}
});
server.start();
try {
client.start();
Assert.assertTrue(serverError.await(5, TimeUnit.SECONDS));
Assert.assertFalse(client.isRunning());
Assert.assertEquals(1, authErrorCount.get());
} finally {
server.halt();
}
}
Aggregations