Package org.jcoredb.fs.impl

Examples of org.jcoredb.fs.impl.FileSystem


 
  @Test
  public void dropTest() throws Exception
  {
    //Create a File System
    IFileSystem fs = new FileSystem(Constants.ROOT_PATH);
    fs.create(0);
    fs.create(Integer.MAX_VALUE);
    fs.close();
   
    //Open the File System
    fs = new FileSystem(Constants.ROOT_PATH);
    fs.open();
    fs.drop(Integer.MAX_VALUE);
   
    assertTrue(new File(Constants.ROOT_PATH + org.jcoredb.system.Constants.PATH_SEP + 0).exists());
    assertFalse(new File(Constants.ROOT_PATH + org.jcoredb.system.Constants.PATH_SEP + Integer.MAX_VALUE).exists());
  }
View Full Code Here


  }
 
  @Test
  public void openAndCloseTest() throws Exception
  {
    IFileSystem fs = new FileSystem(Constants.ROOT_PATH);
    fs.create(0);
   
    fs = new FileSystem(Constants.ROOT_PATH);
    fs.open();
   
    FileSystemConfig cfg = Configs.getFSConfig();   
   
    ISegment[] segments = fs.getContainer(0).getSegments();
   
    assertEquals(cfg.getNumOfSegs(), segments.length);
   
    fs.close();
  }
View Full Code Here

  }
 
  @Test
  public void readTest() throws Exception
  {
    IFileSystem fs = new FileSystem(Constants.ROOT_PATH);
    fs.create(0);
    fs.open();
   
    ArrayList<Block> blocks = new ArrayList<Block>();
    ArrayList<BlockId> blockIds = new ArrayList<BlockId>();
   
    String testStr = "<test> <content> Hello world! </content> </test>";
    byte[] content = testStr.getBytes();
   
    for (int i = 0; i < 200; i++) {

      Block b = new Block(new BlockId(0));
      b.setBytes(content);
     
      blocks.add(b);
     
      BlockId bid = fs.append(b, false);

      blockIds.add(bid);
    }

       
    Block b = fs.read(new BlockId(0,0,111));
   
    assertEquals(testStr, new String(b.getBytes()).substring(0, testStr.length()));
   
    fs.close();
  }
View Full Code Here

 
  @Test
  public void writeTest() throws Exception
  {

    IFileSystem fs = new FileSystem(Constants.ROOT_PATH);
    fs.create(0);
    fs.open();
   
    ArrayList<Block> blocks = new ArrayList<Block>();
    ArrayList<BlockId> blockIds = new ArrayList<BlockId>();
   
    String testStr = "<test> <content> Hello world! </content> </test>";
    byte[] content = testStr.getBytes();
   
    for (int i = 0; i < 200; i++) {

      Block b = new Block(new BlockId(0));
      b.setBytes(content);
     
      blocks.add(b);
     
      BlockId bid = fs.append(b, false);

      blockIds.add(bid);
    }
   
    String newTestStr = "<test> <content> Hello world, again! </content> </test>";
    byte[] newContent = newTestStr.getBytes();
 
    Block b = new Block(blockIds.get(78));
    b.setBytes(newContent);
    fs.write(b);
   
   
    Block rB = fs.read(blockIds.get(78));
   
    assertEquals(newTestStr, new String(rB.getBytes()).substring(0, newTestStr.length()))
  }
View Full Code Here

  }
 
  @Test
  public void appendSingleThreadedTest() throws Exception
  {
    IFileSystem fs = new FileSystem(Constants.ROOT_PATH);
    fs.create(0);
    fs.open();
   
    Block[] blocks = new Block[NUM_OF_BLOCKS_TO_APPEND];
   
    String testStr = "<test> <content> Hello world! </content> </test>";
    byte[] content = testStr.getBytes();
   
    for (int i = 0; i < NUM_OF_BLOCKS_TO_APPEND; i++) {

      Block b = new Block(new BlockId(0));
      b.setBytes(content);     
      blocks[i] = b;
    }

    long startMs = System.currentTimeMillis();
   
    fs.append(blocks, false);
       
    long endMs = System.currentTimeMillis();
   
    System.out.println(endMs - startMs + "ms");
     
View Full Code Here

   * @param args
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
   
    FileSystem fs = new FileSystem(Configs.getFSConfig().getRootDir());
    fs.open();
    FileSystemRegistry.register(Constants.HOST,fs);
   
    HTTPServer srv = new HTTPServer();
    srv.start();
  }
View Full Code Here


  @Test
  public void startHTTPServerTest() throws Exception {
   
    FileSystem fs = new FileSystem("C:\\data\\jcoredb");
    fs.open();
    FileSystemRegistry.register(Constants.HOST, fs);
 
    HTTPServer.main(new String[0]);
   
    System.out.println("Press any key!");
View Full Code Here

  }

  @Test
  public void appendTest() throws Exception {
 
    IFileSystem fs = new FileSystem(Constants.ROOT_PATH);
    fs.create(0);
    fs.open();
   
    Block b = new Block(new BlockId(0));
    byte[] content = "<test> <content> Hello world! </content> </test>".getBytes();
    b.setBytes(content);
   
    Block b2 = new Block(new BlockId(0));
    b.setBytes(content);
   
    BlockId bid = fs.append(b, false);
    BlockId bid2 = fs.append(b2, false);
   
    assertEquals(0, bid.getContainerId());
    assertEquals(0, bid.getSegmentId());
    assertEquals(0, bid.getId());
   
    assertEquals(0, bid2.getContainerId());
    assertEquals(0, bid2.getSegmentId());
    assertEquals(1, bid2.getId());
       
    fs.close();
  }
View Full Code Here

  }
 
  @Test
  public void createTest() throws Exception
  {
    IFileSystem fs = new FileSystem(Constants.ROOT_PATH);
   
    fs.create(0);
   
    assertTrue(new File(Constants.ROOT_PATH + org.jcoredb.system.Constants.PATH_SEP + 0).exists());
   
    fs.create(Integer.MAX_VALUE);
   
    assertTrue(new File(Constants.ROOT_PATH + org.jcoredb.system.Constants.PATH_SEP + Integer.MAX_VALUE).exists());
  }
View Full Code Here

  }
 
  @Test
  public void deleteTest() throws Exception
  {
    IFileSystem fs = new FileSystem(Constants.ROOT_PATH);
    fs.create(0);
    fs.open();
   
    ArrayList<Block> blocks = new ArrayList<Block>();
    ArrayList<BlockId> blockIds = new ArrayList<BlockId>();
   
    for (int i = 0; i < 200; i++) {

      Block b = new Block(new BlockId(0));
      byte[] content = "<test> <content> Hello world! </content> </test>".getBytes();
      b.setBytes(content);
     
      blocks.add(b);
     
      BlockId bid = fs.append(b, false);

      blockIds.add(bid);
    }

    BlockId toDelete = blockIds.get(100);
   
    fs.delete(toDelete, true);
   
    Block b = fs.read(toDelete);
   
    assertEquals(null, b);
   
    fs.close();
  }
View Full Code Here

TOP

Related Classes of org.jcoredb.fs.impl.FileSystem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.