use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class SymbolMapTest method testMapDoesNotExist.
@Test
public void testMapDoesNotExist() throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path().of(configuration.getRoot())) {
try {
new SymbolMapWriter(configuration, path, "x", 0);
Assert.fail();
} catch (CairoException e) {
Assert.assertTrue(Chars.contains(e.getMessage(), "does not exist"));
}
}
});
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class SymbolMapTest method testRollback.
@Test
public void testRollback() throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 1024;
try (Path path = new Path().of(configuration.getRoot())) {
create(path, "x", N, true);
try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0)) {
Rnd rnd = new Rnd();
long prev = -1L;
for (int i = 0; i < N; i++) {
CharSequence cs = rnd.nextChars(10);
long key = writer.put(cs);
Assert.assertEquals(prev + 1, key);
Assert.assertEquals(key, writer.put(cs));
prev = key;
}
writer.rollback(N / 2);
prev = N / 2 - 1;
for (int i = 0; i < N; i++) {
CharSequence cs = rnd.nextChars(10);
long key = writer.put(cs);
Assert.assertEquals(prev + 1, key);
Assert.assertEquals(key, writer.put(cs));
prev = key;
}
}
}
});
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class SymbolMapTest method testShortHeader.
@Test
public void testShortHeader() throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path().of(configuration.getRoot())) {
int plen = path.length();
Assert.assertTrue(configuration.getFilesFacade().touch(path.concat("x").put(".o").$()));
try {
new SymbolMapWriter(configuration, path.trimTo(plen), "x", 0);
Assert.fail();
} catch (CairoException e) {
Assert.assertTrue(Chars.contains(e.getMessage(), "too short"));
}
}
});
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class SymbolMapTest method testTransactionalRead.
@Test
public void testTransactionalRead() throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 1000000;
Rnd rnd = new Rnd();
try (Path path = new Path().of(configuration.getRoot())) {
create(path, "x", N, false);
try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0)) {
long prev = -1L;
for (int i = 0; i < N; i++) {
CharSequence cs = rnd.nextChars(10);
long key = writer.put(cs);
Assert.assertEquals(prev + 1, key);
prev = key;
}
rnd.reset();
try (SymbolMapReaderImpl reader = new SymbolMapReaderImpl(configuration, path, "x", N)) {
for (int i = 0; i < N; i++) {
CharSequence cs = rnd.nextChars(10);
TestUtils.assertEquals(cs, reader.value(i));
Assert.assertEquals(i, reader.getQuick(cs));
}
Assert.assertNull(reader.value(N));
Assert.assertEquals(SymbolTable.VALUE_NOT_FOUND, reader.getQuick("hola"));
Assert.assertEquals(N, writer.put("XYZ"));
// must not be able to read new symbol
Assert.assertNull(reader.value(N));
Assert.assertEquals(SymbolTable.VALUE_NOT_FOUND, reader.getQuick("XYZ"));
reader.updateSymbolCount(N + 1);
TestUtils.assertEquals("XYZ", reader.value(N));
Assert.assertEquals(N, reader.getQuick("XYZ"));
}
}
}
});
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class SymbolMapTest method testAppend.
@Test
public void testAppend() throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 1000;
try (Path path = new Path().of(configuration.getRoot())) {
create(path, "x", N, true);
Rnd rnd = new Rnd();
try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0)) {
long prev = -1L;
for (int i = 0; i < N; i++) {
CharSequence cs = rnd.nextChars(10);
long key = writer.put(cs);
Assert.assertEquals(prev + 1, key);
Assert.assertEquals(key, writer.put(cs));
prev = key;
}
}
try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", N)) {
long prev = N - 1;
// append second batch and check that symbol keys start with N
for (int i = 0; i < N; i++) {
CharSequence cs = rnd.nextChars(10);
long key = writer.put(cs);
Assert.assertEquals(prev + 1, key);
Assert.assertEquals(key, writer.put(cs));
prev = key;
}
// try append first batch - this should return symbol keys starting with 0
rnd.reset();
prev = -1;
for (int i = 0; i < N; i++) {
CharSequence cs = rnd.nextChars(10);
long key = writer.put(cs);
Assert.assertEquals(prev + 1, key);
prev = key;
}
Assert.assertEquals(SymbolTable.VALUE_IS_NULL, writer.put(null));
}
}
});
}
Aggregations