On Friday 07 November 2008 13:53, j16sdiz at freenetproject.org wrote:
> Author: j16sdiz
> Date: 2008-11-07 13:53:18 +0000 (Fri, 07 Nov 2008)
> New Revision: 23373
>
> Added:
> trunk/freenet/test/freenet/support/io/TempBucketTest.java
> Modified:
> trunk/freenet/src/freenet/support/io/TempBucketFactory.java
> trunk/freenet/test/freenet/support/io/BucketTestBase.java
> Log:
> junit for TempBucketFactory
>
> Modified: trunk/freenet/src/freenet/support/io/TempBucketFactory.java
> ===================================================================
> --- trunk/freenet/src/freenet/support/io/TempBucketFactory.java
> 2008-11-07
03:43:25 UTC (rev 23372)
> +++ trunk/freenet/src/freenet/support/io/TempBucketFactory.java
> 2008-11-07
13:53:18 UTC (rev 23373)
> @@ -58,7 +58,7 @@
> /** How old is a long-lived RAMBucket? */
> private final int RAMBUCKET_MAX_AGE = 5*60*1000; // 5mins
> /** How many times the maxRAMBucketSize can a RAMBucket be before it
> gets
migrated? */
> - private final int RAMBUCKET_CONVERSION_FACTOR = 4;
> + final static int RAMBUCKET_CONVERSION_FACTOR = 4;
>
> public class TempBucket implements Bucket {
> /** The underlying bucket itself */
>
> Modified: trunk/freenet/test/freenet/support/io/BucketTestBase.java
> ===================================================================
> --- trunk/freenet/test/freenet/support/io/BucketTestBase.java 2008-11-07
03:43:25 UTC (rev 23372)
> +++ trunk/freenet/test/freenet/support/io/BucketTestBase.java 2008-11-07
13:53:18 UTC (rev 23373)
> @@ -24,6 +24,9 @@
> Bucket bucket = makeBucket(3);
> try {
> assertEquals("Size-0", 0, bucket.size());
> + OutputStream os = bucket.getOutputStream();
> + os.close();
> +
> // Read byte[]
> InputStream is = bucket.getInputStream();
> byte[] data = new byte[10];
> @@ -100,9 +103,14 @@
> freeBucket(bucket);
> }
> }
> +
> + protected boolean canOverwrite = true;
>
> // Write twice -- should overwrite, not append
> public void testReuse() throws IOException {
> + if (!canOverwrite)
> + return;
> +
> Bucket bucket = makeBucket(Math.max(DATA1.length,
> DATA2.length));
> try {
> // Write
>
> Added: trunk/freenet/test/freenet/support/io/TempBucketTest.java
> ===================================================================
> --- trunk/freenet/test/freenet/support/io/TempBucketTest.java
>
(rev 0)
> +++ trunk/freenet/test/freenet/support/io/TempBucketTest.java 2008-11-07
13:53:18 UTC (rev 23373)
> @@ -0,0 +1,176 @@
> +/* This code is part of Freenet. It is distributed under the GNU General
> + * Public License, version 2 (or at your option any later version). See
> + * http://www.gnu.org/ for further details of the GPL. */
> +package freenet.support.io;
> +
> +import java.io.IOException;
> +import java.io.OutputStream;
> +import java.util.Random;
> +
> +import junit.framework.Test;
> +import junit.framework.TestCase;
> +import junit.framework.TestSuite;
> +
> +import org.spaceroots.mantissa.random.MersenneTwister;
> +
> +import freenet.crypt.RandomSource;
> +import freenet.crypt.Yarrow;
> +import freenet.support.Executor;
> +import freenet.support.SerialExecutor;
> +import freenet.support.api.Bucket;
> +import freenet.support.io.TempBucketFactory.TempBucket;
> +
> +public class TempBucketTest extends TestSuite {
> +
> + public static class TempBucketMigrationTest extends TestCase {
> + private RandomSource strongPRNG = new Yarrow();
> + private Random weakPRNG = new MersenneTwister();
> + private Executor exec = new
> SerialExecutor(NativeThread.NORM_PRIORITY);
> + private FilenameGenerator fg;
> +
> + public TempBucketMigrationTest() throws IOException {
> + fg = new FilenameGenerator(weakPRNG, false, null,
> "junit");
> + }
> +
> + public void testRamLimitCreate() throws IOException {
> + TempBucketFactory tbf = new TempBucketFactory(exec, fg,
> 16, 128,
strongPRNG, weakPRNG, false);
> +
> + int maxRamBucket = 128 / 16;
> +
> + // create excess maxTotalRamSize, last one should be on
> disk
> + TempBucket[] b = new TempBucket[maxRamBucket + 1];
> + for (int i = 0; i < maxRamBucket + 1; i++) {
> + b[i] = (TempBucket) tbf.makeBucket(16);
> +
> + OutputStream os = b[i].getOutputStream();
> + os.write(new byte[16]);
> + os.close();
> + }
> +
> + try {
> + assertTrue(b[0].isRAMBucket());
> + assertFalse(b[maxRamBucket].isRAMBucket());
> +
> + // Free some, reused the space
> + b[0].free();
> + b[maxRamBucket].free();
> +
> + b[0] = (TempBucket) tbf.makeBucket(8);
> + b[maxRamBucket] = (TempBucket)
> tbf.makeBucket(8);
> + assertTrue(b[0].isRAMBucket());
> + assertTrue(b[maxRamBucket].isRAMBucket());
Shouldn't one of these be on-disk? You had one on disk, you freed it, now you
have none on disk?
> + } finally {
> + for (Bucket bb : b)
> + bb.free();
> + }
> + }
> +
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
URL:
<https://emu.freenetproject.org/pipermail/devl/attachments/20081108/bf262e20/attachment.pgp>