directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1510115 [13/13] - in /directory/mavibot/trunk: ./ mavibot/ mavibot/src/main/java/org/apache/directory/ mavibot/src/main/java/org/apache/directory/mavibot/ mavibot/src/main/java/org/apache/directory/mavibot/btree/ mavibot/src/main/java/org/...
Date Sun, 04 Aug 2013 09:22:58 GMT
Added: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/LongSerializerTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/LongSerializerTest.java?rev=1510115&view=auto
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/LongSerializerTest.java
(added)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/LongSerializerTest.java
Sun Aug  4 09:22:56 2013
@@ -0,0 +1,359 @@
+/*
+ *  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 org.apache.directory.mavibot.btree.serializer;
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.directory.mavibot.btree.serializer.BufferHandler;
+import org.apache.directory.mavibot.btree.serializer.LongSerializer;
+import org.junit.Test;
+
+
+/**
+ * Test the LongSerializer class
+ * 
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class LongSerializerTest
+{
+    private static LongSerializer serializer = new LongSerializer();
+
+
+    @Test
+    public void testLongSerializer() throws IOException
+    {
+        long value = 0x0000000000000000L;
+        byte[] result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x00, result[7] );
+        assertEquals( ( byte ) 0x00, result[6] );
+        assertEquals( ( byte ) 0x00, result[5] );
+        assertEquals( ( byte ) 0x00, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x0000000000000001L;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x01, result[7] );
+        assertEquals( ( byte ) 0x00, result[6] );
+        assertEquals( ( byte ) 0x00, result[5] );
+        assertEquals( ( byte ) 0x00, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x00000000000000FFL;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0xFF, result[7] );
+        assertEquals( ( byte ) 0x00, result[6] );
+        assertEquals( ( byte ) 0x00, result[5] );
+        assertEquals( ( byte ) 0x00, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x0000000000000100L;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x00, result[7] );
+        assertEquals( ( byte ) 0x01, result[6] );
+        assertEquals( ( byte ) 0x00, result[5] );
+        assertEquals( ( byte ) 0x00, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x000000000000FFFFL;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0xFF, result[7] );
+        assertEquals( ( byte ) 0xFF, result[6] );
+        assertEquals( ( byte ) 0x00, result[5] );
+        assertEquals( ( byte ) 0x00, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x0000000000010000L;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x00, result[7] );
+        assertEquals( ( byte ) 0x00, result[6] );
+        assertEquals( ( byte ) 0x01, result[5] );
+        assertEquals( ( byte ) 0x00, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x0000000000FFFFFFL;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0xFF, result[7] );
+        assertEquals( ( byte ) 0xFF, result[6] );
+        assertEquals( ( byte ) 0xFF, result[5] );
+        assertEquals( ( byte ) 0x00, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x0000000001000000L;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x00, result[7] );
+        assertEquals( ( byte ) 0x00, result[6] );
+        assertEquals( ( byte ) 0x00, result[5] );
+        assertEquals( ( byte ) 0x01, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x000000007FFFFFFFL;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0xFF, result[7] );
+        assertEquals( ( byte ) 0xFF, result[6] );
+        assertEquals( ( byte ) 0xFF, result[5] );
+        assertEquals( ( byte ) 0x7F, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x0000000080000000L;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x00, result[7] );
+        assertEquals( ( byte ) 0x00, result[6] );
+        assertEquals( ( byte ) 0x00, result[5] );
+        assertEquals( ( byte ) 0x80, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x00000000FFFFFFFFL;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0xFF, result[7] );
+        assertEquals( ( byte ) 0xFF, result[6] );
+        assertEquals( ( byte ) 0xFF, result[5] );
+        assertEquals( ( byte ) 0xFF, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x0000000100000000L;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x00, result[7] );
+        assertEquals( ( byte ) 0x00, result[6] );
+        assertEquals( ( byte ) 0x00, result[5] );
+        assertEquals( ( byte ) 0x00, result[4] );
+        assertEquals( ( byte ) 0x01, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x000000FFFFFFFFFFL;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0xFF, result[7] );
+        assertEquals( ( byte ) 0xFF, result[6] );
+        assertEquals( ( byte ) 0xFF, result[5] );
+        assertEquals( ( byte ) 0xFF, result[4] );
+        assertEquals( ( byte ) 0xFF, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x0000010000000000L;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x00, result[7] );
+        assertEquals( ( byte ) 0x00, result[6] );
+        assertEquals( ( byte ) 0x00, result[5] );
+        assertEquals( ( byte ) 0x00, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x01, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x0000FFFFFFFFFFFFL;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0xFF, result[7] );
+        assertEquals( ( byte ) 0xFF, result[6] );
+        assertEquals( ( byte ) 0xFF, result[5] );
+        assertEquals( ( byte ) 0xFF, result[4] );
+        assertEquals( ( byte ) 0xFF, result[3] );
+        assertEquals( ( byte ) 0xFF, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x0001000000000000L;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x00, result[7] );
+        assertEquals( ( byte ) 0x00, result[6] );
+        assertEquals( ( byte ) 0x00, result[5] );
+        assertEquals( ( byte ) 0x00, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x01, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x00FFFFFFFFFFFFFFL;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0xFF, result[7] );
+        assertEquals( ( byte ) 0xFF, result[6] );
+        assertEquals( ( byte ) 0xFF, result[5] );
+        assertEquals( ( byte ) 0xFF, result[4] );
+        assertEquals( ( byte ) 0xFF, result[3] );
+        assertEquals( ( byte ) 0xFF, result[2] );
+        assertEquals( ( byte ) 0xFF, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x0100000000000000L;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x00, result[7] );
+        assertEquals( ( byte ) 0x00, result[6] );
+        assertEquals( ( byte ) 0x00, result[5] );
+        assertEquals( ( byte ) 0x00, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x01, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x7FFFFFFFFFFFFFFFL;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0xFF, result[7] );
+        assertEquals( ( byte ) 0xFF, result[6] );
+        assertEquals( ( byte ) 0xFF, result[5] );
+        assertEquals( ( byte ) 0xFF, result[4] );
+        assertEquals( ( byte ) 0xFF, result[3] );
+        assertEquals( ( byte ) 0xFF, result[2] );
+        assertEquals( ( byte ) 0xFF, result[1] );
+        assertEquals( ( byte ) 0x7F, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x8000000000000000L;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x00, result[7] );
+        assertEquals( ( byte ) 0x00, result[6] );
+        assertEquals( ( byte ) 0x00, result[5] );
+        assertEquals( ( byte ) 0x00, result[4] );
+        assertEquals( ( byte ) 0x00, result[3] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x80, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0xFFFFFFFFFFFFFFFFL;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0xFF, result[7] );
+        assertEquals( ( byte ) 0xFF, result[6] );
+        assertEquals( ( byte ) 0xFF, result[5] );
+        assertEquals( ( byte ) 0xFF, result[4] );
+        assertEquals( ( byte ) 0xFF, result[3] );
+        assertEquals( ( byte ) 0xFF, result[2] );
+        assertEquals( ( byte ) 0xFF, result[1] );
+        assertEquals( ( byte ) 0xFF, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).longValue()
);
+    }
+}

Added: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/RevisionNameSerializerTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/RevisionNameSerializerTest.java?rev=1510115&view=auto
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/RevisionNameSerializerTest.java
(added)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/RevisionNameSerializerTest.java
Sun Aug  4 09:22:56 2013
@@ -0,0 +1,85 @@
+/*
+ *  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 org.apache.directory.mavibot.btree.serializer;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+
+import org.apache.directory.mavibot.btree.RevisionName;
+import org.apache.directory.mavibot.btree.RevisionNameSerializer;
+import org.apache.directory.mavibot.btree.serializer.BufferHandler;
+import org.apache.directory.mavibot.btree.serializer.LongSerializer;
+import org.apache.directory.mavibot.btree.serializer.StringSerializer;
+import org.junit.Test;
+
+
+/**
+ * Test the RevisionNameSerializer class
+ * 
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class RevisionNameSerializerTest
+{
+    private static RevisionNameSerializer serializer = new RevisionNameSerializer();
+
+
+    @Test
+    public void testRevisionNameSerializer() throws IOException
+    {
+        RevisionName value = null;
+
+        try
+        {
+            serializer.serialize( value );
+            fail();
+        }
+        catch ( Exception e )
+        {
+            //exptected
+        }
+
+        // ------------------------------------------------------------------
+        value = new RevisionName( 1L, null );
+        byte[] result = serializer.serialize( value );
+
+        assertEquals( 12, result.length );
+
+        assertEquals( 1L, ( long ) LongSerializer.deserialize( result ) );
+        assertNull( StringSerializer.deserialize( result, 8 ) );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ) );
+
+        // ------------------------------------------------------------------
+        value = new RevisionName( 0L, "" );
+        result = serializer.serialize( value );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ) );
+
+        // ------------------------------------------------------------------
+        value = new RevisionName( 0L, "L\u00E9charny" );
+        result = serializer.serialize( value );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ) );
+    }
+}

Added: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/ShortSerializerTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/ShortSerializerTest.java?rev=1510115&view=auto
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/ShortSerializerTest.java
(added)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/ShortSerializerTest.java
Sun Aug  4 09:22:56 2013
@@ -0,0 +1,107 @@
+/*
+ *  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 org.apache.directory.mavibot.btree.serializer;
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.directory.mavibot.btree.serializer.BufferHandler;
+import org.apache.directory.mavibot.btree.serializer.ShortSerializer;
+import org.junit.Test;
+
+
+/**
+ * Test the ShortSerializer class
+ * 
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class ShortSerializerTest
+{
+    private static ShortSerializer serializer = new ShortSerializer();
+
+
+    @Test
+    public void testShortSerializer() throws IOException
+    {
+        short value = 0x0000;
+        byte[] result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).shortValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x0001;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x01, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).shortValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x00FF;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0xFF, result[1] );
+        assertEquals( ( byte ) 0x00, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).shortValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x0100;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x01, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).shortValue()
);
+
+        // ------------------------------------------------------------------
+        value = 0x7FFF;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0xFF, result[1] );
+        assertEquals( ( byte ) 0x7F, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).shortValue()
);
+
+        // ------------------------------------------------------------------
+        value = ( short ) 0x8000;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x80, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).shortValue()
);
+
+        // ------------------------------------------------------------------
+        value = ( short ) 0xFFFF;
+        result = serializer.serialize( value );
+
+        assertEquals( ( byte ) 0xFF, result[1] );
+        assertEquals( ( byte ) 0xFF, result[0] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ).shortValue()
);
+    }
+}

Added: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/StringSerializerTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/StringSerializerTest.java?rev=1510115&view=auto
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/StringSerializerTest.java
(added)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/serializer/StringSerializerTest.java
Sun Aug  4 09:22:56 2013
@@ -0,0 +1,105 @@
+/*
+ *  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 org.apache.directory.mavibot.btree.serializer;
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.directory.mavibot.btree.serializer.BufferHandler;
+import org.apache.directory.mavibot.btree.serializer.StringSerializer;
+import org.junit.Test;
+
+
+/**
+ * Test the StringSerializer class
+ * 
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class StringSerializerTest
+{
+    private static StringSerializer serializer = new StringSerializer();
+
+
+    @Test
+    public void testStringSerializer() throws IOException
+    {
+        String value = null;
+        byte[] result = serializer.serialize( value );
+
+        assertEquals( 4, result.length );
+        assertEquals( ( byte ) 0xFF, result[0] );
+        assertEquals( ( byte ) 0xFF, result[1] );
+        assertEquals( ( byte ) 0xFF, result[2] );
+        assertEquals( ( byte ) 0xFF, result[3] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ) );
+
+        // ------------------------------------------------------------------
+        value = "";
+        result = serializer.serialize( value );
+
+        assertEquals( 4, result.length );
+        assertEquals( ( byte ) 0x00, result[0] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x00, result[3] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ) );
+
+        // ------------------------------------------------------------------
+        value = "test";
+        result = serializer.serialize( value );
+
+        assertEquals( 8, result.length );
+        assertEquals( ( byte ) 0x00, result[0] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x04, result[3] );
+        assertEquals( 't', result[4] );
+        assertEquals( 'e', result[5] );
+        assertEquals( 's', result[6] );
+        assertEquals( 't', result[7] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ) );
+
+        // ------------------------------------------------------------------
+        value = "L\u00E9charny";
+        result = serializer.serialize( value );
+
+        assertEquals( 13, result.length );
+        assertEquals( ( byte ) 0x00, result[0] );
+        assertEquals( ( byte ) 0x00, result[1] );
+        assertEquals( ( byte ) 0x00, result[2] );
+        assertEquals( ( byte ) 0x09, result[3] );
+        assertEquals( 'L', result[4] );
+        assertEquals( ( byte ) 0xC3, result[5] );
+        assertEquals( ( byte ) 0xA9, result[6] );
+        assertEquals( 'c', result[7] );
+        assertEquals( 'h', result[8] );
+        assertEquals( 'a', result[9] );
+        assertEquals( 'r', result[10] );
+        assertEquals( 'n', result[11] );
+        assertEquals( 'y', result[12] );
+
+        assertEquals( value, serializer.deserialize( new BufferHandler( result ) ) );
+    }
+}

Added: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/util/BulkDataSorterTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/util/BulkDataSorterTest.java?rev=1510115&view=auto
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/util/BulkDataSorterTest.java
(added)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/util/BulkDataSorterTest.java
Sun Aug  4 09:22:56 2013
@@ -0,0 +1,178 @@
+/*
+ *   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 org.apache.directory.mavibot.btree.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.lang.reflect.Array;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Random;
+
+import org.apache.directory.mavibot.btree.Tuple;
+import org.apache.directory.mavibot.btree.util.BulkDataSorter;
+import org.apache.directory.mavibot.btree.util.IntTupleReaderWriter;
+import org.junit.Test;
+
+/**
+ * Test cases for BulkDataSorter.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class BulkDataSorterTest
+{
+
+    private Comparator<Tuple<Integer, Integer>> tupleComp = new Comparator<Tuple<Integer,
Integer>>()
+    {
+        
+        @Override
+        public int compare( Tuple<Integer, Integer> o1, Tuple<Integer, Integer>
o2 )
+        {
+            return o1.getKey().compareTo( o2.getKey() );
+        }
+    };
+
+    
+    @Test
+    public void testSortedFileCount() throws IOException
+    {
+        int count = 7;
+        IntTupleReaderWriter itrw = new IntTupleReaderWriter();
+        Random random = new Random();
+        
+        File dataFile = File.createTempFile( "tuple", ".data" );
+        dataFile.deleteOnExit();
+        DataOutputStream out = new DataOutputStream( new FileOutputStream( dataFile ) );
+        
+        Tuple<Integer, Integer>[] arr = (Tuple<Integer, Integer>[]) Array.newInstance(
Tuple.class, count );
+        
+        for ( int i = 0; i < count; i++ )
+        {
+            int x = random.nextInt(100);
+            //System.out.println(x);
+
+            Tuple<Integer, Integer> t = new Tuple<Integer, Integer>( x, x );
+            
+            arr[i] = t;
+            
+            itrw.writeTuple( t, out );
+        }
+
+        out.close();
+        
+        BulkDataSorter<Integer, Integer> bds = new BulkDataSorter<Integer, Integer>(
itrw, tupleComp, 4 );
+        bds.sort( dataFile );
+        
+        assertEquals(2, bds.getWorkDir().list().length);
+        
+        deleteDir( bds.getWorkDir() );
+    }
+    
+    @Test
+    public void testSortedFileMerge() throws IOException
+    {
+        testSortedFileMerge( 10, 2 );
+        testSortedFileMerge( 100, 7 );
+        testSortedFileMerge( 1000, 25 );
+        testSortedFileMerge( 10000, 100 );
+        testSortedFileMerge( 10000, 101 );
+        testSortedFileMerge( 100000, 501 );
+    }
+    
+    public void testSortedFileMerge(int count, int splitAfter) throws IOException
+    {
+        IntTupleReaderWriter itrw = new IntTupleReaderWriter();
+        Random random = new Random();
+        
+        File dataFile = File.createTempFile( "tuple", ".data" );
+        dataFile.deleteOnExit();
+        
+        DataOutputStream out = new DataOutputStream( new FileOutputStream( dataFile ) );
+        
+        Tuple<Integer, Integer>[] arr = (Tuple<Integer, Integer>[]) Array.newInstance(
Tuple.class, count );
+        
+        int randUpper = count;
+        if(count < 100)
+        {
+            randUpper = 100;
+        }
+        
+        for ( int i = 0; i < count; i++ )
+        {
+            int x = random.nextInt(randUpper);
+            //System.out.println(x);
+
+            Tuple<Integer, Integer> t = new Tuple<Integer, Integer>( x, x );
+            
+            arr[i] = t;
+            
+            itrw.writeTuple( t, out );
+        }
+
+        out.close();
+        
+        BulkDataSorter<Integer, Integer> bds = new BulkDataSorter<Integer, Integer>(
itrw, tupleComp, splitAfter );
+        bds.sort( dataFile );
+        
+        Iterator<Tuple<Integer,Integer>> itr = bds.getMergeSortedTuples();
+        
+        Integer prev = null;
+        while(itr.hasNext())
+        {
+            Tuple<Integer,Integer> t = itr.next();
+            
+            if(prev == null)
+            {
+                prev = t.getKey();
+            }
+            else
+            {
+                assertTrue( prev <= t.getKey() );
+            }
+            
+            //System.out.println(t);
+        }
+        
+        deleteDir( bds.getWorkDir() );
+    }
+    
+    
+    private void deleteDir(File dir)
+    {
+        if(dir.isFile())
+        {
+            dir.delete();
+        }
+        
+        File[] files = dir.listFiles();
+        
+        for(File f: files)
+        {
+            f.delete();
+        }
+        
+        dir.delete();
+    }
+}

Modified: directory/mavibot/trunk/mavibot/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/resources/log4j.properties?rev=1510115&r1=1510114&r2=1510115&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/resources/log4j.properties (original)
+++ directory/mavibot/trunk/mavibot/src/test/resources/log4j.properties Sun Aug  4 09:22:56
2013
@@ -29,4 +29,4 @@ log4j.appender.file.MaxFileSize=7168KB
 log4j.appender.file.MaxBackupIndex=100
 
 #log4j.logger.org=FATAL
-log4j.logger.org.apache.mavibot.btree=ERROR
+log4j.logger.org.apache.directory.mavibot.btree=ERROR

Modified: directory/mavibot/trunk/pom.xml
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/pom.xml?rev=1510115&r1=1510114&r2=1510115&view=diff
==============================================================================
--- directory/mavibot/trunk/pom.xml (original)
+++ directory/mavibot/trunk/pom.xml Sun Aug  4 09:22:56 2013
@@ -21,13 +21,12 @@
   <modelVersion>4.0.0</modelVersion>
 
   <parent>
-    <groupId>org.apache</groupId>
-    <artifactId>apache</artifactId>
-    <version>10</version>
-    <relativePath />
+    <groupId>org.apache.directory.project</groupId>
+    <artifactId>project</artifactId>
+    <version>29</version>
   </parent>
 
-  <groupId>org.apache.labs.mavibot</groupId>
+  <groupId>org.apache.directory.mavibot</groupId>
   <artifactId>mavibot-parent</artifactId>
   <name>ApacheDS MVCC BTree implementation</name>
   <packaging>pom</packaging>



Mime
View raw message