You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directmemory.apache.org by bp...@apache.org on 2012/01/06 13:25:48 UTC

svn commit: r1228146 - in /incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test: MemoryManagerServiceImplTest.java MemoryTestUtils.java

Author: bperroud
Date: Fri Jan  6 12:25:47 2012
New Revision: 1228146

URL: http://svn.apache.org/viewvc?rev=1228146&view=rev
Log:
DIRECTMEMORY-48 : prepare tests to be extended

Added:
    incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryTestUtils.java
Modified:
    incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryManagerServiceImplTest.java

Modified: incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryManagerServiceImplTest.java
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryManagerServiceImplTest.java?rev=1228146&r1=1228145&r2=1228146&view=diff
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryManagerServiceImplTest.java (original)
+++ incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryManagerServiceImplTest.java Fri Jan  6 12:25:47 2012
@@ -19,8 +19,6 @@ package org.apache.directmemory.memory.t
  * under the License.
  */
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Random;
 
 import junit.framework.Assert;
@@ -33,13 +31,14 @@ import org.junit.Test;
 public class MemoryManagerServiceImplTest
 {
 
-    private static final Random R = new Random();
+    protected static final Random R = new Random();
 
-    private static final char PAYLOAD_CHAR = 'X';
+    protected static final byte[] SMALL_PAYLOAD = "ABCD".getBytes();
 
-    private static final String PAYLOAD_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
-    private static final byte[] SMALL_PAYLOAD = "ABCD".getBytes();
+    protected MemoryManagerService getMemoryManagerService()
+    {
+        return new MemoryManagerServiceImpl();
+    }
 
     @Test
     public void testFirstMatchBorderCase()
@@ -51,7 +50,7 @@ public class MemoryManagerServiceImplTes
 
         final int BUFFER_SIZE = 5;
 
-        final MemoryManagerService memoryManagerService = new MemoryManagerServiceImpl();
+        final MemoryManagerService memoryManagerService = getMemoryManagerService();
 
         memoryManagerService.init( 1, BUFFER_SIZE );
 
@@ -72,7 +71,7 @@ public class MemoryManagerServiceImplTes
 
         final int NUMBER_OF_OBJECTS = 4;
 
-        final MemoryManagerServiceImpl memoryManagerService = new MemoryManagerServiceImpl();
+        final MemoryManagerService memoryManagerService = getMemoryManagerService();
 
         memoryManagerService.init( NUMBER_OF_OBJECTS, SMALL_PAYLOAD.length );
 
@@ -95,7 +94,7 @@ public class MemoryManagerServiceImplTes
 
         final int NUMBER_OF_OBJECTS = 10;
 
-        final MemoryManagerServiceImpl memoryManagerService = new MemoryManagerServiceImpl();
+        final MemoryManagerService memoryManagerService = getMemoryManagerService();
         memoryManagerService.init( 1, NUMBER_OF_OBJECTS * SMALL_PAYLOAD.length );
 
         for ( int i = 0; i < NUMBER_OF_OBJECTS; i++ )
@@ -118,7 +117,7 @@ public class MemoryManagerServiceImplTes
         final int NUMBER_OF_OBJECTS = 4;
         final int BUFFER_SIZE = NUMBER_OF_OBJECTS * SMALL_PAYLOAD.length;
 
-        final MemoryManagerServiceImpl memoryManagerService = new MemoryManagerServiceImpl();
+        final MemoryManagerService memoryManagerService = getMemoryManagerService();
 
         memoryManagerService.init( 1, BUFFER_SIZE );
 
@@ -151,13 +150,13 @@ public class MemoryManagerServiceImplTes
         final int NUMBER_OF_OBJECTS = 10;
         final int BUFFER_SIZE = NUMBER_OF_OBJECTS * SMALL_PAYLOAD.length;
 
-        final MemoryManagerServiceImpl memoryManagerService = new MemoryManagerServiceImpl();
+        final MemoryManagerService memoryManagerService = getMemoryManagerService();
 
         memoryManagerService.init( 1, BUFFER_SIZE );
 
         for ( int i = 0; i < NUMBER_OF_OBJECTS; i++ )
         {
-            byte[] payload = generateRandomPayload( SMALL_PAYLOAD.length );
+            byte[] payload = MemoryTestUtils.generateRandomPayload( SMALL_PAYLOAD.length );
             Pointer pointer = memoryManagerService.store( payload );
             Assert.assertNotNull( pointer );
             byte[] fetchedPayload = memoryManagerService.retrieve( pointer );
@@ -172,7 +171,7 @@ public class MemoryManagerServiceImplTes
 
         for ( int i = 0; i < NUMBER_OF_OBJECTS; i++ )
         {
-            byte[] payload = generateRandomPayload( SMALL_PAYLOAD.length );
+            byte[] payload = MemoryTestUtils.generateRandomPayload( SMALL_PAYLOAD.length );
             Pointer pointer = memoryManagerService.store( payload );
             Assert.assertNotNull( pointer );
             byte[] fetchedPayload = memoryManagerService.retrieve( pointer );
@@ -189,7 +188,7 @@ public class MemoryManagerServiceImplTes
         Pointer pointer = null;
         do
         {
-            byte[] payload = generateRandomPayload( R.nextInt( BUFFER_SIZE / 4 + 1 ) );
+            byte[] payload = MemoryTestUtils.generateRandomPayload( R.nextInt( BUFFER_SIZE / 4 + 1 ) );
             pointer = memoryManagerService.store( payload );
             if ( pointer != null && R.nextBoolean() )
             {
@@ -200,14 +199,4 @@ public class MemoryManagerServiceImplTes
 
     }
 
-    private static byte[] generateRandomPayload( int sizeInByte )
-    {
-        final StringBuilder sb = new StringBuilder( sizeInByte );
-        for ( int i = 0; i < sizeInByte; i++ )
-        {
-            sb.append( PAYLOAD_CHARS.charAt( R.nextInt( PAYLOAD_CHARS.length() ) ) );
-        }
-        return sb.toString().getBytes();
-    }
-
 }

Added: incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryTestUtils.java
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryTestUtils.java?rev=1228146&view=auto
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryTestUtils.java (added)
+++ incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryTestUtils.java Fri Jan  6 12:25:47 2012
@@ -0,0 +1,41 @@
+package org.apache.directmemory.memory.test;
+
+/*
+ * 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.
+ */
+
+import java.util.Random;
+
+public class MemoryTestUtils
+{
+
+    private static final String PAYLOAD_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+    private static final Random R = new Random();
+
+    public static byte[] generateRandomPayload( int sizeInByte )
+    {
+        final StringBuilder sb = new StringBuilder( sizeInByte );
+        for ( int i = 0; i < sizeInByte; i++ )
+        {
+            sb.append( PAYLOAD_CHARS.charAt( R.nextInt( PAYLOAD_CHARS.length() ) ) );
+        }
+        return sb.toString().getBytes();
+    }
+
+}