@Before public void before() { System.out.println("************************************************************"); System.out.println("**************************Before****************************"); System.out.println("************************************************************"); work = new File(System.getProperty("java.io.tmpdir", "."), "Puma/20120710/bucket-0"); work.getParentFile().mkdirs(); try { if (work.createNewFile()) System.out.println("create a file! " + work.getAbsolutePath()); work = new File(System.getProperty("java.io.tmpdir", "."), "Puma/20120710/bucket-1"); if (work.createNewFile()) { System.out.println("create a file! " + work.getAbsolutePath()); } } catch (IOException e1) { e1.printStackTrace(); } localBucketIndex.setBaseDir(System.getProperty("java.io.tmpdir", ".") + "/Puma"); localBucketIndex.setBucketFilePrefix("bucket-"); localBucketIndex.setMaxBucketLengthMB(500); System.out.println("*************************************************************"); System.out.println("****************************End******************************"); System.out.println("*************************************************************"); }
@Test public void testInit() throws Exception { System.out.println("************************************************************"); System.out.println("***************************Init*****************************"); System.out.println("************************************************************"); localBucketIndex.start(); System.out.println("*************************"); System.out.println(localBucketIndex.getIndex().get()); System.out.println("*************************"); Assert.assertEquals( "20120710/bucket-0", localBucketIndex.getIndex().get().get(new Sequence(120710, 0))); Assert.assertEquals( "20120710/bucket-1", localBucketIndex.getIndex().get().get(new Sequence(120710, 1))); System.out.println("*************************************************************"); System.out.println("****************************End******************************"); System.out.println("*************************************************************"); }
@Test public void testAddBucket() throws Exception { System.out.println("*************************************************************"); System.out.println("***********************testAddBucket*************************"); System.out.println("*************************************************************"); localBucketIndex.start(); work = new File(System.getProperty("java.io.tmpdir", "."), "Puma/20120711/bucket-0"); work.getParentFile().mkdirs(); try { if (work.createNewFile()) System.out.println("create a file!"); } catch (IOException e1) { e1.printStackTrace(); } Sequence sequence = new Sequence(120711, 0); Bucket bucket = null; try { bucket = new LocalFileBucket(work, sequence, 10, "20120711/bucket-0", false); localBucketIndex.add(bucket); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (StorageClosedException e) { e.printStackTrace(); } Assert.assertEquals("20120711/bucket-0", localBucketIndex.getIndex().get().get(sequence)); try { bucket.stop(); } catch (IOException e) { e.printStackTrace(); } System.out.println("*************************************************************"); System.out.println("****************************End******************************"); System.out.println("*************************************************************"); }
@After public void after() { System.out.println("*************************************************************"); System.out.println("***************************after*****************************"); System.out.println("*************************************************************"); localBucketIndex.stop(); work = new File(System.getProperty("java.io.tmpdir", "."), "Puma"); try { FileUtils.deleteDirectory(work); } catch (IOException e) { e.printStackTrace(); } System.out.println("*************************************************************"); System.out.println("****************************End******************************"); System.out.println("*************************************************************"); }
@Test public void testCopyFromLocal() throws Exception { System.out.println("***************************************************************"); System.out.println("**********************testCopyFromLocal************************"); System.out.println("***************************************************************"); work = new File(System.getProperty("java.io.tmpdir", "."), "Puma/copy/20120710/bucket-0"); work.getParentFile().mkdirs(); try { if (work.createNewFile()) System.out.println("create a file!"); work = new File(System.getProperty("java.io.tmpdir", "."), "Puma/copy/20120710/bucket-1"); if (work.createNewFile()) { System.out.println("create a file!"); } } catch (IOException e1) { e1.printStackTrace(); } this.localBucketIndex.setMaster(false); this.localBucketIndex.start(); try { this.localBucketIndex.copyFromLocal( System.getProperty("java.io.tmpdir", ".").toString() + "/Puma/copy", "20120710/bucket-0"); } catch (StorageClosedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Assert.assertEquals(2, this.localBucketIndex.getIndex().get().size()); work = new File(System.getProperty("java.io.tmpdir", "."), "Puma/copy/20120713/bucket-0"); work.getParentFile().mkdirs(); try { if (work.createNewFile()) System.out.println("create a file!"); } catch (IOException e1) { e1.printStackTrace(); } this.localBucketIndex.start(); try { this.localBucketIndex.copyFromLocal( System.getProperty("java.io.tmpdir", ".") + "/Puma/copy", "20120713/bucket-0"); } catch (StorageClosedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } localBucketIndex.start(); Assert.assertEquals(3, this.localBucketIndex.getIndex().get().size()); Assert.assertEquals(120713, this.localBucketIndex.getIndex().get().lastKey().getCreationDate()); Assert.assertEquals(0, this.localBucketIndex.getIndex().get().lastKey().getNumber()); work = new File(System.getProperty("java.io.tmpdir", "."), "Puma/copy"); for (File file : work.listFiles()) { for (File files : file.listFiles()) { if (files.isFile()) files.delete(); } file.delete(); } work.delete(); System.out.println("*************************************************************"); System.out.println("****************************End******************************"); System.out.println("*************************************************************"); }