From: <mar...@us...> - 2011-02-24 17:49:50
|
Revision: 4245 http://bigdata.svn.sourceforge.net/bigdata/?rev=4245&view=rev Author: martyncutcher Date: 2011-02-24 17:49:44 +0000 (Thu, 24 Feb 2011) Log Message: ----------- Remove unneeded reference to RWSectorStore Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/SectorAllocator.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/rwstore/sector/TestMemoryManager.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/SectorAllocator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/SectorAllocator.java 2011-02-24 17:34:41 UTC (rev 4244) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/SectorAllocator.java 2011-02-24 17:49:44 UTC (rev 4245) @@ -35,7 +35,6 @@ import com.bigdata.rwstore.FixedOutputStream; import com.bigdata.rwstore.IAllocationContext; import com.bigdata.rwstore.IWriteCacheManager; -import com.bigdata.rwstore.RWSectorStore; import com.bigdata.rwstore.RWWriteCacheService; /** @@ -666,7 +665,7 @@ } - public int alloc(RWSectorStore sectorStore, int size, IAllocationContext context) { + public int alloc(int size, IAllocationContext context) { return alloc(size); } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/rwstore/sector/TestMemoryManager.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/rwstore/sector/TestMemoryManager.java 2011-02-24 17:34:41 UTC (rev 4244) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/rwstore/sector/TestMemoryManager.java 2011-02-24 17:49:44 UTC (rev 4245) @@ -10,6 +10,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import com.bigdata.io.DirectBufferPool; +import com.bigdata.rwstore.sector.MemoryManagerResourceError; import com.bigdata.util.concurrent.DaemonThreadFactory; import junit.framework.TestCase; @@ -47,12 +49,10 @@ String retstr = getString(saddr); assertTrue(helloWorld.equals(retstr)); - - System.out.println(helloWorld + " allocated address: " + saddr + " returned: " + retstr); } private void installMemoryManager() { - manager = new MemoryManager(5 * sectorSize, sectorSize); + manager = new MemoryManager(DirectBufferPool.INSTANCE, 10); } /** @@ -64,7 +64,7 @@ while (--i > 0) { // final int sector = r.nextInt(12); final int sector = r.nextInt(32 * 1024); - final int bit = r.nextInt(64 * 1024); + final int bit = r.nextInt(32 * 1024); final int rwaddr = SectorAllocator.makeAddr(sector, bit); final int rsector = SectorAllocator.getSectorIndex(rwaddr); final int rbit = SectorAllocator.getSectorOffset(rwaddr); @@ -76,14 +76,26 @@ installMemoryManager(); for (int i = 0; i < 20; i++) { - doStressAllocations(manager, true, 80000, 5 + r.nextInt(200)); + doStressAllocations(manager, true, 50000, 5 + r.nextInt(5000)); } } + public void testSimpleBlob() { + installMemoryManager(); + + String blob = new String(c_testData, 0, 11000); + + final long saddr = allocate(manager, blob); + + String retstr = getString(saddr); + + assertTrue(blob.equals(retstr)); + } + public void testAllocationContexts() { installMemoryManager(); - final IMemoryManager context = manager.createAllocationContext(); + IMemoryManager context = manager.createAllocationContext(); for (int i = 0; i < 500; i++) { doStressAllocations(context, false, 5000, 5 + r.nextInt(3000)); context.clear(); @@ -133,30 +145,34 @@ int f = r.nextInt(addrs.size()); long faddr = ((Long) addrs.remove(f)).longValue(); mm.free(faddr); - // System.out.println("freeing: " + faddr); frees++; } } } catch (MemoryManagerResourceError err) { // all okay } - - System.out.println("Committed " + allocs + " allocations, and " + frees + " frees"); } private String getString(long saddr) { - final ByteBuffer ret = manager.get(saddr)[0]; - final byte[] data; - if (ret.isDirect()) { - ByteBuffer indbuf = ByteBuffer.allocate(ret.remaining()); - data = indbuf.array(); - indbuf.put(ret); - indbuf.flip(); - } else { - data = ret.array(); + StringBuffer sb = new StringBuffer(); + + final ByteBuffer[] bufs = manager.get(saddr); + + for (int i = 0; i < bufs.length; i++) { + final byte[] data; + if (bufs[i].isDirect()) { + ByteBuffer indbuf = ByteBuffer.allocate(bufs[i].remaining()); + data = indbuf.array(); + indbuf.put(bufs[i]); + indbuf.flip(); + } else { + data = bufs[i].array(); + } + + sb.append(new String(data)); } - return new String(data); + return sb.toString(); } private long allocate(final IMemoryManager mm, String val) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |