geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upthewatersp...@apache.org
Subject [46/51] [abbrv] incubator-geode git commit: GEODE-827: split the unit test up into two
Date Fri, 22 Jan 2016 23:26:27 GMT
GEODE-827: split the unit test up into two

The integration test methods in SimpleMemoryAllocatorFillPatternJUnitTest
have been moved to the new SimpleMemoryAllocatorFillPatternIntegrationTest.

Also the time the integration tests run has been changed from 2 minutes to 10 seconds.
These unit test methods have also been refactored to remove duplicate code.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/b370a703
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/b370a703
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/b370a703

Branch: refs/heads/wan_cq_donation
Commit: b370a703c0e089559d9bea2010b457af070cbdea
Parents: 94835c6
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Thu Jan 21 16:17:35 2016 -0800
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Fri Jan 22 11:28:29 2016 -0800

----------------------------------------------------------------------
 ...moryAllocatorFillPatternIntegrationTest.java | 246 ++++++++++++
 ...mpleMemoryAllocatorFillPatternJUnitTest.java | 377 +------------------
 2 files changed, 262 insertions(+), 361 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b370a703/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternIntegrationTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternIntegrationTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternIntegrationTest.java
new file mode 100644
index 0000000..239cbc8
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternIntegrationTest.java
@@ -0,0 +1,246 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.offheap;
+
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Tests fill pattern validation for the {@link SimpleMemoryAllocatorImpl}.
+ */
+@Category(IntegrationTest.class)
+public class SimpleMemoryAllocatorFillPatternIntegrationTest {
+  private static Random random = ThreadLocalRandom.current();
+
+  /**
+   * Chunk operation types.
+   */
+  static enum Operation {
+    ALLOCATE,
+    FREE,
+    WRITE;
+    
+    // Holds all Operation values
+    private static Operation[] values = Operation.values(); 
+    
+    static Operation randomOperation() {
+      return values[random.nextInt(values.length)];
+    }
+  };
+  
+  /** Number of worker threads for advanced tests. */
+  private static final int WORKER_THREAD_COUNT = 5;
+  
+  /** Size of single test slab.*/
+  private static final int SLAB_SIZE = 1024 * 1024 * 50;
+  
+  /** Maximum number of bytes a worker thread can allocate during advanced tests.  */
+  private static final int MAX_WORKER_ALLOCATION_TOTAL_SIZE = SLAB_SIZE / WORKER_THREAD_COUNT
/ 2;
+  
+  /** Maximum allocation for a single Chunk.  */
+  private static final int MAX_WORKER_ALLOCATION_SIZE = 512;
+  
+  /** Canned data for write operations. */
+  private static final byte[] WRITE_BYTES = new String("Some string data.").getBytes();
+  
+  /** Minimum size for write operations. */
+  private static final int MIN_WORKER_ALLOCATION_SIZE = WRITE_BYTES.length;
+
+  /** Runtime for worker threads. */
+  private static final long RUN_TIME_IN_MILLIS = 1 * 1000 * 5;
+  
+  /** Chunk size for basic huge allocation test. */
+  private static final int HUGE_CHUNK_SIZE = 1024 * 200;
+  
+  /** Our test victim. */
+  private SimpleMemoryAllocatorImpl allocator = null;
+  
+  /** Our test victim's memory slab. */
+  private UnsafeMemoryChunk slab = null;
+
+  /**
+   * Enables fill validation and creates the test victim.
+   */
+  @Before
+  public void setUp() throws Exception {
+    System.setProperty("gemfire.validateOffHeapWithFill", "true");
+    this.slab = new UnsafeMemoryChunk(SLAB_SIZE);
+    this.allocator = SimpleMemoryAllocatorImpl.create(new NullOutOfOffHeapMemoryListener(),
new NullOffHeapMemoryStats(), new UnsafeMemoryChunk[]{this.slab});
+  }
+
+  /**
+   * Frees off heap memory.
+   */
+  @After
+  public void tearDown() throws Exception {
+    SimpleMemoryAllocatorImpl.freeOffHeapMemory();
+    System.clearProperty("gemfire.validateOffHeapWithFill");
+  }
+  
+  /**
+   * This test hammers a SimpleMemoryAllocatorImpl with multiple threads exercising
+   * the fill validation of tiny Chunks for one minute.  This, of course, exercises many
aspects of
+   * the SimpleMemoryAllocatorImpl and its helper classes.
+   * @throws Exception
+   */
+  @Test
+  public void testFillPatternAdvancedForTinyAllocations() throws Exception { 
+    doFillPatternAdvancedTest(new ChunkSizer() {
+      @Override
+      public int allocationSize() {
+        int allocation = random.nextInt(MAX_WORKER_ALLOCATION_SIZE+1);
+        
+        while(allocation < MIN_WORKER_ALLOCATION_SIZE) {
+          allocation = random.nextInt(MAX_WORKER_ALLOCATION_SIZE+1);
+        }
+        return allocation;
+      }
+    });
+  }
+
+  /**
+   * This test hammers a SimpleMemoryAllocatorImpl with multiple threads exercising
+   * the fill validation of huge Chunks for one minute.  This, of course, exercises many
aspects of
+   * the SimpleMemoryAllocatorImpl and its helper classes.
+   * @throws Exception
+   */
+  @Test
+  public void testFillPatternAdvancedForHugeAllocations() throws Exception {
+    doFillPatternAdvancedTest(new ChunkSizer() {
+      @Override
+      public int allocationSize() {
+        return HUGE_CHUNK_SIZE;
+      }
+    });
+  }
+  
+  private interface ChunkSizer {
+    int allocationSize();
+  }
+  
+  private void doFillPatternAdvancedTest(final ChunkSizer chunkSizer) throws InterruptedException
{
+    // Used to manage worker thread completion
+    final CountDownLatch latch = new CountDownLatch(WORKER_THREAD_COUNT);
+    
+    // Use to track any errors the worker threads will encounter
+    final List<Throwable> threadErrorList = Collections.synchronizedList(new LinkedList<Throwable>());
+    
+    /*
+     * Start up a number of worker threads.  These threads will randomly allocate, free,
+     * and write to Chunks.
+     */
+    for(int i = 0;i < WORKER_THREAD_COUNT;++i) {
+      new Thread(new Runnable() {
+        // Total allocation in bytes for this thread
+        private int totalAllocation = 0;
+        
+        // List of Chunks allocated by this thread
+        private List<Chunk> chunks = new LinkedList<Chunk>();
+        
+        // Time to end thread execution
+        private long endTime = System.currentTimeMillis() + RUN_TIME_IN_MILLIS;
+        
+        /**
+         * Allocates a chunk and adds it to the thread's Chunk list.
+         */
+        private void allocate() {          
+          int allocation = chunkSizer.allocationSize();
+          Chunk chunk = (Chunk) allocator.allocate(allocation, null);
+          
+          // This should always work just after allocation
+          chunk.validateFill();
+          
+          chunks.add(chunk);
+          totalAllocation += chunk.getSize();
+        }
+        
+        /**
+         * Frees a random chunk from the Chunk list.
+         */
+        private void free() {
+          Chunk chunk = chunks.remove(random.nextInt(chunks.size()));
+          totalAllocation -= chunk.getSize();
+          
+          /*
+           * Chunk is filled here but another thread may have already grabbed it so we
+           * cannot validate the fill.
+           */
+          chunk.release(); 
+        }
+        
+        /**
+         * Writes canned data to a random Chunk from the Chunk list.
+         */
+        private void write() {
+          Chunk chunk = chunks.get(random.nextInt(chunks.size()));
+          chunk.writeBytes(0, WRITE_BYTES);
+        }
+        
+        /**
+         * Randomly selects Chunk operations and executes them
+         * for a period of time.  Collects any error thrown during execution.
+         */
+        @Override
+        public void run() {
+          try {
+            for(long currentTime = System.currentTimeMillis();currentTime < endTime;currentTime
= System.currentTimeMillis()) {
+              Operation op = (totalAllocation == 0 ? Operation.ALLOCATE : (totalAllocation
>= MAX_WORKER_ALLOCATION_TOTAL_SIZE ? Operation.FREE : Operation.randomOperation()));
+              switch(op) {
+              case ALLOCATE:
+                allocate();
+                break;
+              case FREE:
+                free();
+                break;
+              case WRITE:
+                write();
+                break;
+              }
+            }
+          } catch (Throwable t) {
+            threadErrorList.add(t);
+          } finally {
+            latch.countDown();
+          }
+       }        
+      }).start();
+    }
+    
+    // Make sure each thread ended cleanly
+    assertTrue(latch.await(2, TimeUnit.MINUTES));
+    
+    // Fail on the first error we find
+    if(!threadErrorList.isEmpty()) {
+      fail(threadErrorList.get(0).getMessage());
+    }
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b370a703/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java
index 12f5d22..21c9835 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java
@@ -17,20 +17,14 @@
 package com.gemstone.gemfire.internal.offheap;
 
 import static org.junit.Assert.*;
-
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Random;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import static com.googlecode.catchexception.CatchException.*;
 
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 import junit.framework.TestCase;
 
@@ -38,49 +32,15 @@ import junit.framework.TestCase;
  * Tests fill pattern validation for the {@link SimpleMemoryAllocatorImpl}.
  * @author rholmes
  */
-@Category(IntegrationTest.class)
+@Category(UnitTest.class)
 public class SimpleMemoryAllocatorFillPatternJUnitTest {
-  /**
-   * Chunk operation types.
-   * @author rholmes
-   */
-  static enum Operation {
-    ALLOCATE,
-    FREE,
-    WRITE;
-    
-    // Unfortunately we cannot use ThreadLocalRandom in order to maintain 1.6 compatibility...
-    private static Random random = new Random(System.currentTimeMillis());
-    
-    // Holds all Operation values
-    private static Operation[] values = Operation.values(); 
-    
-    static Operation randomOperation() {
-      return values[random.nextInt(values.length)];
-    }
-  };
-  
-  /** Number of worker threads for advanced tests. */
-  private static final int WORKER_THREAD_COUNT = 5;
   
   /** Size of single test slab.*/
   private static final int SLAB_SIZE = 1024 * 1024 * 50;
   
-  /** Maximum number of bytes a worker thread can allocate during advanced tests.  */
-  private static final int MAX_WORKER_ALLOCATION_TOTAL_SIZE = SLAB_SIZE / WORKER_THREAD_COUNT
/ 2;
-  
-  /** Maximum allocation for a single Chunk.  */
-  private static final int MAX_WORKER_ALLOCATION_SIZE = 512;
-  
   /** Canned data for write operations. */
   private static final byte[] WRITE_BYTES = new String("Some string data.").getBytes();
   
-  /** Minimum size for write operations. */
-  private static final int MIN_WORKER_ALLOCATION_SIZE = WRITE_BYTES.length;
-
-  /** Runtime for worker threads. */
-  private static final long RUN_TIME_IN_MILLIS = 1 * 1000 * 60;
-  
   /** Chunk size for basic huge allocation test. */
   private static final int HUGE_CHUNK_SIZE = 1024 * 200;
   
@@ -124,64 +84,7 @@ public class SimpleMemoryAllocatorFillPatternJUnitTest {
    */
   @Test
   public void testFillPatternBasicForTinyAllocations() throws Exception {
-    /*
-     * Pull a chunk off the fragment.  This will have no fill because
-     * it is a "fresh" chunk.
-     */
-    Chunk chunk = (Chunk) this.allocator.allocate(1024, null);
-
-    /*
-     * Chunk should have valid fill from initial fragment allocation.
-     */    
-    try {
-      chunk.validateFill();
-    } catch(IllegalStateException e) {
-      fail(e.getMessage());
-    }
-    
-    // "Dirty" the chunk so the release has something to fill over
-    chunk.writeBytes(Chunk.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
-
-    // This should free the Chunk (ref count == 1)
-    chunk.release();
-
-    /*
-     * This chunk should have a fill because it was reused from the
-     * free list (assuming no fragmentation at this point...)
-     */
-    chunk = (Chunk) this.allocator.allocate(1024, null);
-    
-    // Make sure we have a fill this time
-    try {
-      chunk.validateFill();
-    } catch(IllegalStateException e) {
-      TestCase.fail("Chunk fill validation failed: " + e.getMessage());
-    }
-    
-    // Give the fill code something to write over during the release
-    chunk.writeBytes(Chunk.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
-    chunk.release();
-
-    // Again, make sure the release implemented the fill
-    try {
-      chunk.validateFill();
-    } catch(IllegalStateException e) {
-      TestCase.fail("Chunk fill validation failed: " + e.getMessage());
-    }
-
-    // "Dirty up" the free chunk
-    chunk.writeBytes(Chunk.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
-    
-    boolean failure = false;
-
-    // One final check for validateFill()
-    try {
-      chunk.validateFill();
-    } catch(IllegalStateException e) {
-      failure = true;
-    }
-    
-    assertTrue(failure);
+    doFillPatternBasic(1024);
   }
   
   /**
@@ -190,20 +93,20 @@ public class SimpleMemoryAllocatorFillPatternJUnitTest {
    */
   @Test
   public void testFillPatternBasicForHugeAllocations() throws Exception {
+    doFillPatternBasic(HUGE_CHUNK_SIZE);
+  }
+  
+  private void doFillPatternBasic(final int chunkSize) {
     /*
      * Pull a chunk off the fragment.  This will have no fill because
      * it is a "fresh" chunk.
      */
-    Chunk chunk = (Chunk) this.allocator.allocate(HUGE_CHUNK_SIZE, null);
+    Chunk chunk = (Chunk) this.allocator.allocate(chunkSize, null);
 
     /*
      * Chunk should have valid fill from initial fragment allocation.
      */
-    try {
-      chunk.validateFill();
-    } catch(IllegalStateException e) {
-      fail(e.getMessage());
-    }
+    chunk.validateFill();
          
     // "Dirty" the chunk so the release has something to fill over
     chunk.writeBytes(Chunk.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
@@ -215,276 +118,28 @@ public class SimpleMemoryAllocatorFillPatternJUnitTest {
      * This chunk should have a fill because it was reused from the
      * free list (assuming no fragmentation at this point...)
      */
-    chunk = (Chunk) this.allocator.allocate(HUGE_CHUNK_SIZE, null);
+    chunk = (Chunk) this.allocator.allocate(chunkSize, null);
     
     // Make sure we have a fill this time
-    try {
-      chunk.validateFill();
-    } catch(IllegalStateException e) {
-      TestCase.fail("Chunk fill validation failed: " + e.getMessage());
-    }
+    chunk.validateFill();
     
     // Give the fill code something to write over during the release
     chunk.writeBytes(Chunk.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
     chunk.release();
 
     // Again, make sure the release implemented the fill
-    try {
-      chunk.validateFill();
-    } catch(IllegalStateException e) {
-      TestCase.fail("Chunk fill validation failed: " + e.getMessage());
-    }
+    chunk.validateFill();
 
     // "Dirty up" the free chunk
     chunk.writeBytes(Chunk.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
     
-    boolean failure = false;
-
-    // One final check for validateFill()
-    try {
-      chunk.validateFill();
-    } catch(IllegalStateException e) {
-      failure = true;
-    }
+    catchException(chunk).validateFill();
+    assertTrue(caughtException() instanceof IllegalStateException);
+    assertEquals("Fill pattern violated for chunk " + chunk.getMemoryAddress() + " with size
" + chunk.getSize(), caughtException().getMessage());
     
-    assertTrue(failure);
   }
 
   /**
-   * This test hammers a SimpleMemoryAllocatorImpl with multiple threads exercising
-   * the fill validation of tiny Chunks for one minute.  This, of course, exercises many
aspects of
-   * the SimpleMemoryAllocatorImpl and its helper classes.
-   * @throws Exception
-   */
-  @Test
-  public void testFillPatternAdvancedForTinyAllocations() throws Exception { 
-    // Used to manage worker thread completion
-    final CountDownLatch latch = new CountDownLatch(WORKER_THREAD_COUNT);
-    
-    // Use to track any errors the worker threads will encounter
-    final List<Throwable> threadErrorList = Collections.synchronizedList(new LinkedList<Throwable>());
-    
-    /*
-     * Start up a number of worker threads.  These threads will randomly allocate, free,
-     * and write to Chunks.
-     */
-    for(int i = 0;i < WORKER_THREAD_COUNT;++i) {
-      new Thread(new Runnable() {
-        // Total allocation in bytes for this thread
-        private int totalAllocation = 0;
-        
-        // List of Chunks allocated by this thread
-        private List<Chunk> chunks = new LinkedList<Chunk>();
-        
-        // Time to end thread execution
-        private long endTime = System.currentTimeMillis() + RUN_TIME_IN_MILLIS;
-        
-        // Randomizer used for random Chunk size allocation
-        private Random random = new Random(endTime);
-        
-        /**
-         * Returns an allocation size between a min and max constraint.
-         */
-        private int allocationSize() {
-          int allocation = random.nextInt(MAX_WORKER_ALLOCATION_SIZE+1);
-          
-          while(allocation < MIN_WORKER_ALLOCATION_SIZE) {
-            allocation = random.nextInt(MAX_WORKER_ALLOCATION_SIZE+1);
-          }
-
-          return allocation;
-        }
-        
-        /**
-         * Allocates a chunk and adds it to the thread's Chunk list.
-         */
-        private void allocate() {          
-          int allocation = allocationSize();
-          Chunk chunk = (Chunk) allocator.allocate(allocation, null);
-
-          // This should always work just after allocation
-          chunk.validateFill();          
-
-          chunks.add(chunk);
-          totalAllocation += chunk.getSize();
-        }
-        
-        /**
-         * Frees a random chunk from the Chunk list.
-         */
-        private void free() {
-          Chunk chunk = chunks.remove(random.nextInt(chunks.size()));
-          totalAllocation -= chunk.getSize();
-          
-          /*
-           * Chunk is filled here but another thread may have already grabbed it so we
-           * cannot validate the fill.
-           */
-          chunk.release();
-        }
-        
-        /**
-         * Writes canned data to a random Chunk from the Chunk list.
-         */
-        private void write() {
-          Chunk chunk = chunks.get(random.nextInt(chunks.size()));
-          chunk.writeBytes(0, WRITE_BYTES);
-        }
-        
-        /**
-         * Randomly selects Chunk operations and executes them
-         * for a period of time.  Collects any error thrown during execution.
-         */
-        @Override
-        public void run() {
-          try {
-            for(long currentTime = System.currentTimeMillis();currentTime < endTime;currentTime
= System.currentTimeMillis()) {
-              Operation op = (totalAllocation == 0 ? Operation.ALLOCATE : (totalAllocation
>= MAX_WORKER_ALLOCATION_TOTAL_SIZE ? Operation.FREE : Operation.randomOperation()));
-              switch(op) {
-              case ALLOCATE:
-                allocate();
-                break;
-              case FREE:
-                free();
-                break;
-              case WRITE:
-                write();
-                break;
-              }
-            }
-          } catch (Throwable t) {
-            threadErrorList.add(t);
-          } finally {
-            latch.countDown();
-          }
-       }        
-      }).start();
-    }
-    
-    // Make sure each thread ended cleanly
-    assertTrue(latch.await(2, TimeUnit.MINUTES));
-    
-    // Fail on the first error we find
-    if(!threadErrorList.isEmpty()) {
-      fail(threadErrorList.get(0).getMessage());
-    }
-  }
-
-  /**
-   * This test hammers a SimpleMemoryAllocatorImpl with multiple threads exercising
-   * the fill validation of huge Chunks for one minute.  This, of course, exercises many
aspects of
-   * the SimpleMemoryAllocatorImpl and its helper classes.
-   * @throws Exception
-   */
-  @Test
-  public void testFillPatternAdvancedForHugeAllocations() throws Exception { 
-    // Used to manage worker thread completion
-    final CountDownLatch latch = new CountDownLatch(WORKER_THREAD_COUNT);
-    
-    // Use to track any errors the worker threads will encounter
-    final List<Throwable> threadErrorList = Collections.synchronizedList(new LinkedList<Throwable>());
-    
-    /*
-     * Start up a number of worker threads.  These threads will randomly allocate, free,
-     * and write to Chunks.
-     */
-    for(int i = 0;i < WORKER_THREAD_COUNT;++i) {
-      new Thread(new Runnable() {
-        // Total allocation in bytes for this thread
-        private int totalAllocation = 0;
-        
-        // List of Chunks allocated by this thread
-        private List<Chunk> chunks = new LinkedList<Chunk>();
-        
-        // Time to end thread execution
-        private long endTime = System.currentTimeMillis() + RUN_TIME_IN_MILLIS;
-        
-        // Randomizer used for random Chunk size allocation
-        private Random random = new Random(endTime);
-        
-        /**
-         * Returns an allocation size between a min and max constraint.
-         */
-        private int allocationSize() {
-          return HUGE_CHUNK_SIZE;
-        }
-        
-        /**
-         * Allocates a chunk and adds it to the thread's Chunk list.
-         */
-        private void allocate() {          
-          int allocation = allocationSize();
-          Chunk chunk = (Chunk) allocator.allocate(allocation, null);
-          
-          // This should always work just after allocation
-          chunk.validateFill();
-          
-          chunks.add(chunk);
-          totalAllocation += chunk.getSize();
-        }
-        
-        /**
-         * Frees a random chunk from the Chunk list.
-         */
-        private void free() {
-          Chunk chunk = chunks.remove(random.nextInt(chunks.size()));
-          totalAllocation -= chunk.getSize();
-          
-          /*
-           * Chunk is filled here but another thread may have already grabbed it so we
-           * cannot validate the fill.
-           */
-          chunk.release(); 
-        }
-        
-        /**
-         * Writes canned data to a random Chunk from the Chunk list.
-         */
-        private void write() {
-          Chunk chunk = chunks.get(random.nextInt(chunks.size()));
-          chunk.writeBytes(0, WRITE_BYTES);
-        }
-        
-        /**
-         * Randomly selects Chunk operations and executes them
-         * for a period of time.  Collects any error thrown during execution.
-         */
-        @Override
-        public void run() {
-          try {
-            for(long currentTime = System.currentTimeMillis();currentTime < endTime;currentTime
= System.currentTimeMillis()) {
-              Operation op = (totalAllocation == 0 ? Operation.ALLOCATE : (totalAllocation
>= MAX_WORKER_ALLOCATION_TOTAL_SIZE ? Operation.FREE : Operation.randomOperation()));
-              switch(op) {
-              case ALLOCATE:
-                allocate();
-                break;
-              case FREE:
-                free();
-                break;
-              case WRITE:
-                write();
-                break;
-              }
-            }
-          } catch (Throwable t) {
-            threadErrorList.add(t);
-          } finally {
-            latch.countDown();
-          }
-       }        
-      }).start();
-    }
-    
-    // Make sure each thread ended cleanly
-    assertTrue(latch.await(2, TimeUnit.MINUTES));
-    
-    // Fail on the first error we find
-    if(!threadErrorList.isEmpty()) {
-      fail(threadErrorList.get(0).getMessage());
-    }
-  }
-  
-  /**
    * This tests that fill validation is working properly on newly created fragments after
    * a compaction.
    * @throws Exception


Mime
View raw message