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 08:21:34 UTC

svn commit: r1227997 - in /incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test: BaseTest.java MemoryManagerServiceImplTest.java MemoryManagerTest.java NIOTest.java

Author: bperroud
Date: Fri Jan  6 07:21:33 2012
New Revision: 1227997

URL: http://svn.apache.org/viewvc?rev=1227997&view=rev
Log:
DIRECTMEMORY-55 : fix tests, reformat

Modified:
    incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/BaseTest.java
    incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryManagerServiceImplTest.java
    incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryManagerTest.java
    incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/NIOTest.java

Modified: incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/BaseTest.java
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/BaseTest.java?rev=1227997&r1=1227996&r2=1227997&view=diff
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/BaseTest.java (original)
+++ incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/BaseTest.java Fri Jan  6 07:21:33 2012
@@ -158,7 +158,7 @@ public class BaseTest
             {
                 assertEquals( lastP.end + 1, p.start );
             }
-            assertEquals( p.end - p.start, payload.length );
+            assertEquals( p.getCapacity(), payload.length );
             lastP = p;
             logger.info( "---" );
         }

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=1227997&r1=1227996&r2=1227997&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 07:21:33 2012
@@ -2,19 +2,19 @@ package org.apache.directmemory.memory.t
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
  * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
+ * 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
- *
+ * 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
+ * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
@@ -25,101 +25,107 @@ import org.apache.directmemory.memory.Me
 import org.apache.directmemory.memory.Pointer;
 import org.junit.Test;
 
-public class MemoryManagerServiceImplTest {
-	
-	private static final byte[] SMALL_PAYLOAD = "ABCD".getBytes();
-
-	@Test
-	public void testFirstMatchBorderCase() {
-		
-		// Storing a first payload of 4 bytes, 1 byte remaining in the buffer. When storing a second 4 bytes payload, an BufferOverflowException is thrown instead of an easy check.
-		
-		final int BUFFER_SIZE = 5;
-		
-		final MemoryManagerServiceImpl memoryManagerService = new MemoryManagerServiceImpl();
-		
-		memoryManagerService.init(1, BUFFER_SIZE);
-		
-		Pointer pointer1 = memoryManagerService.store(SMALL_PAYLOAD);
-		Assert.assertNotNull(pointer1);
-		
-		Pointer pointer2 = memoryManagerService.store(SMALL_PAYLOAD);
-		Assert.assertNull(pointer2);
-		
-	}
-	
-	@Test
-	public void testAllocateMultipleBuffers() {
-
-		// Initializing 4 buffers of 4 bytes, MemoryManagerService should search for available space in another buffer.
-		
-		final int NUMBER_OF_OBJECTS = 4;
-		
-		final MemoryManagerServiceImpl memoryManagerService = new MemoryManagerServiceImpl();
-		
-		memoryManagerService.init(NUMBER_OF_OBJECTS, SMALL_PAYLOAD.length);
-		 
-		for (int i = 0; i < NUMBER_OF_OBJECTS; i++) {
-			Pointer pointer = memoryManagerService.store(SMALL_PAYLOAD);
-			Assert.assertNotNull(pointer);
-		}
-		
-		Pointer pointerNull = memoryManagerService.store(SMALL_PAYLOAD);
-		Assert.assertNull(pointerNull);
-	}
-	
-	
-	@Test
-	public void testByteLeaking() {
-		
-		// Initializing 1 buffer of 10*4 bytes, should be able to allocate 10 objects of 4 bytes.
-		
-		final int NUMBER_OF_OBJECTS = 10;
-		
-		final MemoryManagerServiceImpl memoryManagerService = new MemoryManagerServiceImpl(); 
-		memoryManagerService.init(1, NUMBER_OF_OBJECTS * SMALL_PAYLOAD.length);
-		
-		for (int i = 0; i < NUMBER_OF_OBJECTS; i++) {
-			Pointer pointer = memoryManagerService.store(SMALL_PAYLOAD);
-			Assert.assertNotNull(pointer);
-		}
-		
-		Pointer pointerNull = memoryManagerService.store(SMALL_PAYLOAD);
-		Assert.assertNull(pointerNull);
-	}
-	
-	
-	@Test
-	public void testReportCorrectUsedMemory() {
-
-		// Initializing 1 buffer of 4*4 bytes, storing and freeing and storing again should report correct numbers.
-		
-		final int NUMBER_OF_OBJECTS = 4;
-		final int BUFFER_SIZE = NUMBER_OF_OBJECTS * SMALL_PAYLOAD.length;
-
-		final MemoryManagerServiceImpl memoryManagerService = new MemoryManagerServiceImpl();
-		
-		memoryManagerService.init(1, BUFFER_SIZE);
-		
-		Pointer lastPointer = null;
-		for (int i = 0; i < NUMBER_OF_OBJECTS; i++) {
-			Pointer pointer = memoryManagerService.store(SMALL_PAYLOAD);
-			Assert.assertNotNull(pointer);
-			lastPointer = pointer;
-		}
-		
-		// Buffer is fully used.
-		Assert.assertEquals(BUFFER_SIZE, memoryManagerService.getBuffers().get(0).used());
-
-		Assert.assertNotNull(lastPointer);
-		memoryManagerService.free( lastPointer );
-		
-		Pointer pointerNotNull = memoryManagerService.store(SMALL_PAYLOAD);
-		Assert.assertNotNull(pointerNotNull);
-		
-		// Buffer again fully used.
-		Assert.assertEquals(BUFFER_SIZE, memoryManagerService.getBuffers().get(0).used());
-		
-	}
-	
+public class MemoryManagerServiceImplTest
+{
+
+    private static final byte[] SMALL_PAYLOAD = "ABCD".getBytes();
+
+    @Test
+    public void testFirstMatchBorderCase()
+    {
+
+        // Storing a first payload of 4 bytes, 1 byte remaining in the buffer. When storing a second 4 bytes payload, an BufferOverflowException is thrown instead of an easy check.
+
+        final int BUFFER_SIZE = 5;
+
+        final MemoryManagerServiceImpl memoryManagerService = new MemoryManagerServiceImpl();
+
+        memoryManagerService.init( 1, BUFFER_SIZE );
+
+        Pointer pointer1 = memoryManagerService.store( SMALL_PAYLOAD );
+        Assert.assertNotNull( pointer1 );
+
+        Pointer pointer2 = memoryManagerService.store( SMALL_PAYLOAD );
+        Assert.assertNull( pointer2 );
+
+    }
+
+    @Test
+    public void testAllocateMultipleBuffers()
+    {
+
+        // Initializing 4 buffers of 4 bytes, MemoryManagerService should search for available space in another buffer.
+
+        final int NUMBER_OF_OBJECTS = 4;
+
+        final MemoryManagerServiceImpl memoryManagerService = new MemoryManagerServiceImpl();
+
+        memoryManagerService.init( NUMBER_OF_OBJECTS, SMALL_PAYLOAD.length );
+
+        for ( int i = 0; i < NUMBER_OF_OBJECTS; i++ )
+        {
+            Pointer pointer = memoryManagerService.store( SMALL_PAYLOAD );
+            Assert.assertNotNull( pointer );
+        }
+
+        Pointer pointerNull = memoryManagerService.store( SMALL_PAYLOAD );
+        Assert.assertNull( pointerNull );
+    }
+
+    @Test
+    public void testByteLeaking()
+    {
+
+        // Initializing 1 buffer of 10*4 bytes, should be able to allocate 10 objects of 4 bytes.
+
+        final int NUMBER_OF_OBJECTS = 10;
+
+        final MemoryManagerServiceImpl memoryManagerService = new MemoryManagerServiceImpl();
+        memoryManagerService.init( 1, NUMBER_OF_OBJECTS * SMALL_PAYLOAD.length );
+
+        for ( int i = 0; i < NUMBER_OF_OBJECTS; i++ )
+        {
+            Pointer pointer = memoryManagerService.store( SMALL_PAYLOAD );
+            Assert.assertNotNull( pointer );
+        }
+
+        Pointer pointerNull = memoryManagerService.store( SMALL_PAYLOAD );
+        Assert.assertNull( pointerNull );
+    }
+
+    @Test
+    public void testReportCorrectUsedMemory()
+    {
+
+        // Initializing 1 buffer of 4*4 bytes, storing and freeing and storing again should report correct numbers.
+
+        final int NUMBER_OF_OBJECTS = 4;
+        final int BUFFER_SIZE = NUMBER_OF_OBJECTS * SMALL_PAYLOAD.length;
+
+        final MemoryManagerServiceImpl memoryManagerService = new MemoryManagerServiceImpl();
+
+        memoryManagerService.init( 1, BUFFER_SIZE );
+
+        Pointer lastPointer = null;
+        for ( int i = 0; i < NUMBER_OF_OBJECTS; i++ )
+        {
+            Pointer pointer = memoryManagerService.store( SMALL_PAYLOAD );
+            Assert.assertNotNull( pointer );
+            lastPointer = pointer;
+        }
+
+        // Buffer is fully used.
+        Assert.assertEquals( BUFFER_SIZE, memoryManagerService.getBuffers().get( 0 ).used() );
+
+        Assert.assertNotNull( lastPointer );
+        memoryManagerService.free( lastPointer );
+
+        Pointer pointerNotNull = memoryManagerService.store( SMALL_PAYLOAD );
+        Assert.assertNotNull( pointerNotNull );
+
+        // Buffer again fully used.
+        Assert.assertEquals( BUFFER_SIZE, memoryManagerService.getBuffers().get( 0 ).used() );
+
+    }
+
 }

Modified: incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryManagerTest.java?rev=1227997&r1=1227996&r2=1227997&view=diff
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryManagerTest.java (original)
+++ incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/MemoryManagerTest.java Fri Jan  6 07:21:33 2012
@@ -58,7 +58,7 @@ public class MemoryManagerTest
         logger.info( "stored" );
         assertNotNull( p );
         //assertEquals(size,p.end);
-        assertEquals( size, p.end - p.start );
+        assertEquals( size, p.getCapacity() );
         assertEquals( size, MemoryManager.getActiveBuffer().used() );
         MemoryManager.free( p );
         assertEquals( 0, MemoryManager.getActiveBuffer().used() );

Modified: incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/NIOTest.java
URL: http://svn.apache.org/viewvc/incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/NIOTest.java?rev=1227997&r1=1227996&r2=1227997&view=diff
==============================================================================
--- incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/NIOTest.java (original)
+++ incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/memory/test/NIOTest.java Fri Jan  6 07:21:33 2012
@@ -80,7 +80,7 @@ public class NIOTest
 
         assertNotNull( check );
 
-        assertEquals( size, p.end - p.start );
+        assertEquals( size, p.getCapacity() );
         logger.info( "end" );
     }