Search in sources :

Example 26 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class FailedTests method testDataStructure.

// cannot capture reference to a structure
@Test
public void testDataStructure() {
    Bytes bytes = new ImperativeCompiler().compile(0, // 
    "" + // 
    "constant p = fix :p struct (() | pointer::p +next);" + // 
    "declare r = & new p (+next = null,);" + "0");
    assertNotNull(bytes);
    System.out.println(bytes);
}
Also used : Bytes(suite.primitive.Bytes) ImperativeCompiler(suite.ip.ImperativeCompiler) FunRbTreeTest(suite.fp.FunRbTreeTest) Test(org.junit.Test)

Example 27 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class B_TreeTest method testInsertPerformance.

@Test
public void testInsertPerformance() throws IOException {
    int nKeys = 16384;
    keys = Ints_.toArray(nKeys, i -> i);
    int pageSize = 4096;
    Path path = Constants.tmp("b_tree-file");
    for (int i = 0; i < nKeys; i++) {
        int j = random.nextInt(nKeys);
        Integer temp = keys[i];
        keys[i] = keys[j];
        keys[j] = temp;
    }
    Files.deleteIfExists(path);
    B_TreeBuilder<Integer, Bytes> builder = new B_TreeBuilder<>(serialize.int_, serialize.bytes(64));
    try (JournalledPageFile jpf = JournalledFileFactory.journalled(path, pageSize);
        B_Tree<Integer, Bytes> b_tree = builder.build(jpf, comparator, 9999)) {
        new Profiler().profile(() -> {
            b_tree.create();
            for (int i = 0; i < nKeys; i++) {
                int key = keys[i];
                b_tree.put(key, To.bytes(Integer.toString(key)));
            }
            jpf.commit();
            jpf.sync();
        });
    }
}
Also used : Object_(suite.util.Object_) B_TreeBuilder(suite.btree.impl.B_TreeBuilder) Files(java.nio.file.Files) Constants(suite.Constants) Bytes(suite.primitive.Bytes) Profiler(suite.sample.Profiler) IOException(java.io.IOException) Random(java.util.Random) Test(org.junit.Test) To(suite.util.To) Serialize(suite.util.Serialize) JournalledPageFile(suite.file.JournalledPageFile) Pair(suite.adt.pair.Pair) Assert.assertNull(org.junit.Assert.assertNull) Ints_(suite.primitive.Ints_) Comparator(java.util.Comparator) Path(java.nio.file.Path) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) JournalledFileFactory(suite.file.impl.JournalledFileFactory) Path(java.nio.file.Path) Bytes(suite.primitive.Bytes) Profiler(suite.sample.Profiler) B_TreeBuilder(suite.btree.impl.B_TreeBuilder) JournalledPageFile(suite.file.JournalledPageFile) Test(org.junit.Test)

Example 28 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class FileSystemTest method testWriteOneFile.

private void testWriteOneFile(FileSystem fs) {
    Bytes filename = To.bytes("file");
    Bytes data = To.bytes("data");
    FileSystemMutator fsm = fs.mutate();
    fsm.replace(filename, data);
    assertEquals(1, fsm.list(filename, null).size());
    assertEquals(data, fsm.read(filename));
    fsm.replace(filename, null);
    assertEquals(0, fsm.list(filename, null).size());
}
Also used : Bytes(suite.primitive.Bytes)

Example 29 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class FileSystemTest method testWriteFiles.

private void testWriteFiles(FileSystem fs) throws IOException {
    Streamlet<Path> paths = FileUtil.findPaths(Paths.get("src/test/java/"));
    FileSystemMutator fsm = fs.mutate();
    for (Path path : paths) {
        String filename = path.toString().replace(File.separatorChar, '/');
        Bytes name = Bytes.of(filename.getBytes(Constants.charset));
        fsm.replace(name, Bytes.of(Files.readAllBytes(path)));
    }
}
Also used : Path(java.nio.file.Path) Bytes(suite.primitive.Bytes)

Example 30 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class FileSystemTest method testReadFile.

private void testReadFile(FileSystem fs) throws IOException {
    String filename = "src/test/java/suite/fs/FileSystemTest.java";
    FileSystemMutator fsm = fs.mutate();
    Bytes name = Bytes.of(filename.getBytes(Constants.charset));
    Copy.stream(fsm.read(name).collect(As::inputStream), System.out);
}
Also used : Bytes(suite.primitive.Bytes)

Aggregations

Bytes (suite.primitive.Bytes)56 Test (org.junit.Test)18 BytesBuilder (suite.primitive.Bytes.BytesBuilder)8 IOException (java.io.IOException)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Pair (suite.adt.pair.Pair)4 OutputStream (java.io.OutputStream)3 Path (java.nio.file.Path)3 To (suite.util.To)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Constants (suite.Constants)2 Amd64Interpret (suite.assembler.Amd64Interpret)2 Condition (suite.concurrent.Condition)2 Extent (suite.file.ExtentAllocator.Extent)2 JournalledPageFile (suite.file.JournalledPageFile)2 ImperativeCompiler (suite.ip.ImperativeCompiler)2 DataInput_ (suite.util.DataInput_)2