/** * Serializes the object and write it out to the given position. * <p> * TODO: make this take a ded as well. * @return true unless error * @param obj * @param pos * @throws IOException */ protected boolean writeObject( Serializable obj, long pos ) throws IOException { byte[] data = elementSerializer.serialize( obj ); write( new IndexedDiskElementDescriptor( pos, data.length ), data ); return true; }
/** * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object o) { if (o instanceof IndexedDiskElementDescriptor) { return compareTo((IndexedDiskElementDescriptor) o) == 0; } return false; }
/** * Serializes the object and write it out to the given position. * <p> * TODO: make this take a ded as well. * @return true unless error * @param obj * @param pos * @throws IOException */ protected boolean writeObject( Serializable obj, long pos ) throws IOException { byte[] data = elementSerializer.serialize( obj ); write( new IndexedDiskElementDescriptor( pos, data.length ), data ); return true; }
new IndexedDiskElementDescriptor(0, (int) keyFile.length() - IndexedDisk.HEADER_SIZE_BYTES));
keyFile.readObject( new IndexedDiskElementDescriptor( 0, (int) keyFile.length() - IndexedDisk.HEADER_SIZE_BYTES ) );
ded = new IndexedDiskElementDescriptor( dataFile.length(), data.length );
ded = new IndexedDiskElementDescriptor(dataFile.length(), data.length);
for ( int i = 0; i < tries; i++ ) cacheCount.put( "key:" + i, new IndexedDiskElementDescriptor(i, i) ); for ( int i = 0; i < tries; i++ ) cacheSize.put( "key:" + i, new IndexedDiskElementDescriptor(i, i) );
for ( int i = 0; i < tries; i++ ) cacheCount.put( "key:" + i, new IndexedDiskElementDescriptor(i, i) ); for ( int i = 0; i < tries; i++ ) cacheSize.put( "key:" + i, new IndexedDiskElementDescriptor(i, i) );
/** * Verify that the overlap check returns true when there are no overlaps. */ public void testCheckForDedOverlaps_noOverlap() { // SETUP IndexedDiskCacheAttributes cattr = getCacheAttributes(); cattr.setCacheName("testCheckForDedOverlaps_noOverlap"); cattr.setDiskPath("target/test-sandbox/UnitTest"); IndexedDiskCache<String, String> disk = new IndexedDiskCache<String, String>(cattr); int numDescriptors = 5; int pos = 0; IndexedDiskElementDescriptor[] sortedDescriptors = new IndexedDiskElementDescriptor[numDescriptors]; for (int i = 0; i < numDescriptors; i++) { IndexedDiskElementDescriptor descriptor = new IndexedDiskElementDescriptor(pos, i * 2); pos = pos + (i * 2) + IndexedDisk.HEADER_SIZE_BYTES; sortedDescriptors[i] = descriptor; } // DO WORK boolean result = disk.checkForDedOverlaps(sortedDescriptors); // VERIFY assertTrue("There should be no overlap. it should be ok", result); }
/** * Verify that the overlap check returns true when there are no overlaps. */ public void testCheckForDedOverlaps_noOverlap() { // SETUP IndexedDiskCacheAttributes cattr = getCacheAttributes(); cattr.setCacheName( "testCheckForDedOverlaps_noOverlap" ); cattr.setDiskPath( "target/test-sandbox/UnitTest" ); IndexedDiskCache<String, String> disk = new IndexedDiskCache<String, String>( cattr ); int numDescriptors = 5; int pos = 0; IndexedDiskElementDescriptor[] sortedDescriptors = new IndexedDiskElementDescriptor[numDescriptors]; for ( int i = 0; i < numDescriptors; i++ ) { IndexedDiskElementDescriptor descriptor = new IndexedDiskElementDescriptor( pos, i * 2 ); pos = pos + ( i * 2 ) + IndexedDisk.HEADER_SIZE_BYTES; sortedDescriptors[i] = descriptor; } // DO WORK boolean result = disk.checkForDedOverlaps( sortedDescriptors ); // VERIFY assertTrue( "There should be no overlap. it should be ok", result ); }
/** * Verify that the overlap check returns false when there are overlaps. */ public void testCheckForDedOverlaps_overlaps() { // SETUP IndexedDiskCacheAttributes cattr = getCacheAttributes(); cattr.setCacheName("testCheckForDedOverlaps_overlaps"); cattr.setDiskPath("target/test-sandbox/UnitTest"); IndexedDiskCache<String, String> disk = new IndexedDiskCache<String, String>(cattr); int numDescriptors = 5; int pos = 0; IndexedDiskElementDescriptor[] sortedDescriptors = new IndexedDiskElementDescriptor[numDescriptors]; for (int i = 0; i < numDescriptors; i++) { IndexedDiskElementDescriptor descriptor = new IndexedDiskElementDescriptor(pos, i * 2); // don't add the header + IndexedDisk.RECORD_HEADER; pos = pos + (i * 2); sortedDescriptors[i] = descriptor; } // DO WORK boolean result = disk.checkForDedOverlaps(sortedDescriptors); // VERIFY assertFalse("There should be overlaps. it should be not ok", result); }
/** * Verify that the overlap check returns false when there are overlaps. */ public void testCheckForDedOverlaps_overlaps() { // SETUP IndexedDiskCacheAttributes cattr = getCacheAttributes(); cattr.setCacheName( "testCheckForDedOverlaps_overlaps" ); cattr.setDiskPath( "target/test-sandbox/UnitTest" ); IndexedDiskCache<String, String> disk = new IndexedDiskCache<String, String>( cattr ); int numDescriptors = 5; int pos = 0; IndexedDiskElementDescriptor[] sortedDescriptors = new IndexedDiskElementDescriptor[numDescriptors]; for ( int i = 0; i < numDescriptors; i++ ) { IndexedDiskElementDescriptor descriptor = new IndexedDiskElementDescriptor( pos, i * 2 ); // don't add the header + IndexedDisk.RECORD_HEADER; pos = pos + ( i * 2 ); sortedDescriptors[i] = descriptor; } // DO WORK boolean result = disk.checkForDedOverlaps( sortedDescriptors ); // VERIFY assertFalse( "There should be overlaps. it should be not ok", result ); }