You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directmemory.apache.org by ol...@apache.org on 2012/10/01 22:57:52 UTC
svn commit: r1392595 [10/15] - in /directmemory/lightning/trunk: ./
lightning-api/ lightning-api/src/ lightning-api/src/main/
lightning-api/src/main/java/ lightning-api/src/main/java/org/
lightning-api/src/main/java/org/apache/ lightning-api/src/main/j...
Added: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/ComplexClassHierarchyTestCase.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/ComplexClassHierarchyTestCase.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/ComplexClassHierarchyTestCase.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/ComplexClassHierarchyTestCase.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,324 @@
+/*
+ * 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.directmemory.lightning;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+
+import org.apache.directmemory.lightning.Lightning;
+import org.apache.directmemory.lightning.Serializer;
+import org.apache.directmemory.lightning.base.AbstractSerializerDefinition;
+import org.apache.directmemory.lightning.internal.util.DebugLogger;
+import org.apache.directmemory.lightning.io.SerializerInputStream;
+import org.apache.directmemory.lightning.io.SerializerOutputStream;
+import org.apache.directmemory.lightning.metadata.Attribute;
+import org.apache.directmemory.lightning.metadata.ClassDefinitionContainer;
+import org.junit.Test;
+
+public class ComplexClassHierarchyTestCase
+{
+
+ @Test
+ public void testSimpleObject()
+ throws Exception
+ {
+ Serializer serializer =
+ Lightning.newBuilder().logger( new DebugLogger() ).debugCacheDirectory( new File( "target" ) ).serializerDefinitions( new SerializerDefinition() ).build();
+
+ ClassDefinitionContainer container = serializer.getClassDefinitionContainer();
+
+ Serializer remoteSerializer =
+ Lightning.newBuilder().logger( new DebugLogger() ).serializerDefinitions( new SerializerDefinition() ).build();
+
+ remoteSerializer.setClassDefinitionContainer( container );
+
+ Foo foo = new Foo();
+ foo.setId( 10000 );
+ foo.setName( "SomeName" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+ out.writeObject( foo );
+
+ assertNotNull( baos );
+ assertNotNull( out );
+ assertNotNull( baos.toByteArray() );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+ Object value = in.readObject();
+ assertNotNull( value );
+ assertEquals( foo, value );
+ }
+
+ @Test
+ public void testSomeMoreComplexObjectWithOneDefinition()
+ throws Exception
+ {
+ Serializer serializer =
+ Lightning.newBuilder().logger( new DebugLogger() ).debugCacheDirectory( new File( "target" ) ).serializerDefinitions( new SerializerDefinition() ).build();
+
+ ClassDefinitionContainer container = serializer.getClassDefinitionContainer();
+
+ Serializer remoteSerializer =
+ Lightning.newBuilder().logger( new DebugLogger() ).serializerDefinitions( new SerializerDefinition() ).build();
+
+ remoteSerializer.setClassDefinitionContainer( container );
+
+ Foo foo = new Foo();
+ foo.setId( 10000 );
+ foo.setName( "SomeName" );
+
+ Complex complex = new Complex();
+ complex.setFoo( foo );
+ complex.setBar( Bar.SomeOtherValue );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+ out.writeObject( complex );
+
+ assertNotNull( baos );
+ assertNotNull( out );
+ assertNotNull( baos.toByteArray() );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+ Object value = in.readObject();
+ assertNotNull( value );
+ assertEquals( complex, value );
+ }
+
+ @Test
+ public void testSomeMoreComplexObjectWithTwoDefinition()
+ throws Exception
+ {
+ Serializer serializer =
+ Lightning.newBuilder().logger( new DebugLogger() ).debugCacheDirectory( new File( "target" ) ).serializerDefinitions( new ParentSerializerDefinition() ).build();
+
+ ClassDefinitionContainer container = serializer.getClassDefinitionContainer();
+
+ Serializer remoteSerializer =
+ Lightning.newBuilder().logger( new DebugLogger() ).serializerDefinitions( new ParentSerializerDefinition() ).build();
+
+ remoteSerializer.setClassDefinitionContainer( container );
+
+ Foo foo = new Foo();
+ foo.setId( 10000 );
+ foo.setName( "SomeName" );
+
+ Complex complex = new Complex();
+ complex.setFoo( foo );
+ complex.setBar( Bar.SomeOtherValue );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+ out.writeObject( complex );
+
+ assertNotNull( baos );
+ assertNotNull( out );
+ assertNotNull( baos.toByteArray() );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+ Object value = in.readObject();
+ assertNotNull( value );
+ assertEquals( complex, value );
+ }
+
+ public static class SerializerDefinition
+ extends AbstractSerializerDefinition
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( Foo.class ).attributes();
+ serialize( Complex.class ).attributes();
+ }
+ }
+
+ public static class ParentSerializerDefinition
+ extends AbstractSerializerDefinition
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( Foo.class ).attributes();
+
+ install( new ChildSerializerDefinition() );
+ }
+ }
+
+ public static class ChildSerializerDefinition
+ extends AbstractSerializerDefinition
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( Complex.class ).attributes();
+ }
+ }
+
+ public static class Foo
+ {
+
+ @Attribute
+ private int id;
+
+ @Attribute
+ private String name;
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public void setId( int id )
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + id;
+ result = prime * result + ( ( name == null ) ? 0 : name.hashCode() );
+ return result;
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ return true;
+ if ( obj == null )
+ return false;
+ if ( getClass() != obj.getClass() )
+ return false;
+ Foo other = (Foo) obj;
+ if ( id != other.id )
+ return false;
+ if ( name == null )
+ {
+ if ( other.name != null )
+ return false;
+ }
+ else if ( !name.equals( other.name ) )
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Foo [id=" + id + ", name=" + name + "]";
+ }
+ }
+
+ public static class Complex
+ {
+
+ @Attribute
+ private Foo foo;
+
+ @Attribute
+ private Bar bar;
+
+ public Foo getFoo()
+ {
+ return foo;
+ }
+
+ public void setFoo( Foo foo )
+ {
+ this.foo = foo;
+ }
+
+ public Bar getBar()
+ {
+ return bar;
+ }
+
+ public void setBar( Bar bar )
+ {
+ this.bar = bar;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ( ( bar == null ) ? 0 : bar.hashCode() );
+ result = prime * result + ( ( foo == null ) ? 0 : foo.hashCode() );
+ return result;
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ return true;
+ if ( obj == null )
+ return false;
+ if ( getClass() != obj.getClass() )
+ return false;
+ Complex other = (Complex) obj;
+ if ( bar != other.bar )
+ return false;
+ if ( foo == null )
+ {
+ if ( other.foo != null )
+ return false;
+ }
+ else if ( !foo.equals( other.foo ) )
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Complex [foo=" + foo + ", bar=" + bar + "]";
+ }
+ }
+
+ public static enum Bar
+ {
+ SomeValue, SomeOtherValue, SomeTotallyDifferentValue
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/ComplexClassHierarchyTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/ComplexClassHierarchyTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/GenericTypedTestCase.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/GenericTypedTestCase.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/GenericTypedTestCase.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/GenericTypedTestCase.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,458 @@
+/*
+ * 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.directmemory.lightning;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.PrintStream;
+import java.util.List;
+
+import org.apache.directmemory.lightning.Lightning;
+import org.apache.directmemory.lightning.Serializer;
+import org.apache.directmemory.lightning.base.AbstractSerializerDefinition;
+import org.apache.directmemory.lightning.io.SerializerInputStream;
+import org.apache.directmemory.lightning.io.SerializerOutputStream;
+import org.apache.directmemory.lightning.logging.LogLevel;
+import org.apache.directmemory.lightning.logging.LoggerAdapter;
+import org.apache.directmemory.lightning.metadata.Attribute;
+import org.apache.directmemory.lightning.metadata.ClassDefinitionContainer;
+import org.junit.Test;
+
+public class GenericTypedTestCase
+{
+
+ @Test
+ public void testSimpleObject()
+ throws Exception
+ {
+ Serializer serializer =
+ Lightning.newBuilder().logger( new DebugLogger() ).debugCacheDirectory( new File( "target" ) ).serializerDefinitions( new SerializerDefinition() ).build();
+
+ ClassDefinitionContainer container = serializer.getClassDefinitionContainer();
+
+ Serializer remoteSerializer =
+ Lightning.newBuilder().logger( new DebugLogger() ).serializerDefinitions( new SerializerDefinition() ).build();
+
+ remoteSerializer.setClassDefinitionContainer( container );
+
+ Foo foo = new Foo();
+ foo.setId( 10000 );
+ // foo.setName("SomeName");
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+ out.writeObject( foo );
+
+ assertNotNull( baos );
+ assertNotNull( out );
+ assertNotNull( baos.toByteArray() );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+ Object value = in.readObject();
+ assertNotNull( value );
+ assertEquals( foo, value );
+ }
+
+ @Test
+ public void testSomeMoreComplexObjectWithOneDefinition()
+ throws Exception
+ {
+ Serializer serializer =
+ Lightning.newBuilder().logger( new DebugLogger() ).debugCacheDirectory( new File( "target" ) ).serializerDefinitions( new SerializerDefinition() ).build();
+
+ ClassDefinitionContainer container = serializer.getClassDefinitionContainer();
+
+ Serializer remoteSerializer =
+ Lightning.newBuilder().logger( new DebugLogger() ).serializerDefinitions( new SerializerDefinition() ).build();
+
+ remoteSerializer.setClassDefinitionContainer( container );
+
+ Foo foo = new Foo();
+ foo.setId( 10000 );
+ // foo.setName("SomeName");
+
+ Complex complex = new Complex();
+ complex.setFoo( foo );
+ complex.setBar( Bar.SomeOtherValue );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+ out.writeObject( complex );
+
+ assertNotNull( baos );
+ assertNotNull( out );
+ assertNotNull( baos.toByteArray() );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+ Object value = in.readObject();
+ assertNotNull( value );
+ assertEquals( complex, value );
+ }
+
+ @Test
+ public void testSomeMoreComplexObjectWithTwoDefinition()
+ throws Exception
+ {
+ Serializer serializer =
+ Lightning.newBuilder().logger( new DebugLogger() ).debugCacheDirectory( new File( "target" ) ).serializerDefinitions( new ParentSerializerDefinition() ).build();
+
+ ClassDefinitionContainer container = serializer.getClassDefinitionContainer();
+
+ Serializer remoteSerializer =
+ Lightning.newBuilder().logger( new DebugLogger() ).serializerDefinitions( new ParentSerializerDefinition() ).build();
+
+ remoteSerializer.setClassDefinitionContainer( container );
+
+ Foo foo = new Foo();
+ foo.setId( 10000 );
+ // foo.setName("SomeName");
+
+ Complex complex = new Complex();
+ complex.setFoo( foo );
+ complex.setBar( Bar.SomeOtherValue );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+ out.writeObject( complex );
+
+ assertNotNull( baos );
+ assertNotNull( out );
+ assertNotNull( baos.toByteArray() );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+ Object value = in.readObject();
+ assertNotNull( value );
+ assertEquals( complex, value );
+ }
+
+ public static class SerializerDefinition
+ extends AbstractSerializerDefinition
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( Foo.class ).attributes();
+ serialize( Complex.class ).attributes();
+ }
+ }
+
+ public static class ParentSerializerDefinition
+ extends AbstractSerializerDefinition
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( Foo.class ).attributes();
+
+ install( new ChildSerializerDefinition() );
+ }
+ }
+
+ public static class ChildSerializerDefinition
+ extends AbstractSerializerDefinition
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( Complex.class ).attributes();
+ }
+ }
+
+ public static class Foo
+ {
+
+ @Attribute
+ private int id;
+
+ @Attribute
+ private List<String> names;
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public void setId( int id )
+ {
+ this.id = id;
+ }
+
+ public List<String> getNames()
+ {
+ return names;
+ }
+
+ public void setNames( List<String> names )
+ {
+ this.names = names;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + id;
+ // result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ return true;
+ if ( obj == null )
+ return false;
+ if ( getClass() != obj.getClass() )
+ return false;
+ Foo other = (Foo) obj;
+ if ( id != other.id )
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Foo [id=" + id + ", names=" + names + "]";
+ }
+ }
+
+ public static class Complex
+ {
+
+ @Attribute
+ private Foo foo;
+
+ @Attribute
+ private Bar bar;
+
+ public Foo getFoo()
+ {
+ return foo;
+ }
+
+ public void setFoo( Foo foo )
+ {
+ this.foo = foo;
+ }
+
+ public Bar getBar()
+ {
+ return bar;
+ }
+
+ public void setBar( Bar bar )
+ {
+ this.bar = bar;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ( ( bar == null ) ? 0 : bar.hashCode() );
+ result = prime * result + ( ( foo == null ) ? 0 : foo.hashCode() );
+ return result;
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ return true;
+ if ( obj == null )
+ return false;
+ if ( getClass() != obj.getClass() )
+ return false;
+ Complex other = (Complex) obj;
+ if ( bar != other.bar )
+ return false;
+ if ( foo == null )
+ {
+ if ( other.foo != null )
+ return false;
+ }
+ else if ( !foo.equals( other.foo ) )
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Complex [foo=" + foo + ", bar=" + bar + "]";
+ }
+ }
+
+ public static enum Bar
+ {
+ SomeValue, SomeOtherValue, SomeTotallyDifferentValue
+ }
+
+ public static class DebugLogger
+ extends LoggerAdapter
+ {
+
+ @Override
+ public boolean isLogLevelEnabled( LogLevel logLevel )
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isTraceEnabled()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isDebugEnabled()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isInfoEnabled()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isWarnEnabled()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isErrorEnabled()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isFatalEnabled()
+ {
+ return true;
+ }
+
+ @Override
+ public void trace( String message )
+ {
+ log( LogLevel.Trace, message, null );
+ }
+
+ @Override
+ public void trace( String message, Throwable throwable )
+ {
+ log( LogLevel.Trace, message, throwable );
+ }
+
+ @Override
+ public void debug( String message )
+ {
+ log( LogLevel.Debug, message, null );
+ }
+
+ @Override
+ public void debug( String message, Throwable throwable )
+ {
+ log( LogLevel.Debug, message, throwable );
+ }
+
+ @Override
+ public void info( String message )
+ {
+ log( LogLevel.Info, message, null );
+ }
+
+ @Override
+ public void info( String message, Throwable throwable )
+ {
+ log( LogLevel.Info, message, throwable );
+ }
+
+ @Override
+ public void warn( String message )
+ {
+ log( LogLevel.Warn, message, null );
+ }
+
+ @Override
+ public void warn( String message, Throwable throwable )
+ {
+ log( LogLevel.Warn, message, throwable );
+ }
+
+ @Override
+ public void error( String message )
+ {
+ log( LogLevel.Error, message, null );
+ }
+
+ @Override
+ public void error( String message, Throwable throwable )
+ {
+ log( LogLevel.Error, message, throwable );
+ }
+
+ @Override
+ public void fatal( String message )
+ {
+ log( LogLevel.Fatal, message, null );
+ }
+
+ @Override
+ public void fatal( String message, Throwable throwable )
+ {
+ log( LogLevel.Fatal, message, throwable );
+ }
+
+ private void log( LogLevel logLevel, String message, Throwable throwable )
+ {
+ PrintStream stream;
+ if ( throwable != null )
+ {
+ stream = System.err;
+ }
+ else
+ {
+ stream = System.out;
+ }
+
+ stream.println( getName() + " - " + logLevel.name() + ": " + message );
+ if ( throwable != null )
+ {
+ throwable.printStackTrace();
+ }
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/GenericTypedTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/GenericTypedTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/PropertyFinderTestCase.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/PropertyFinderTestCase.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/PropertyFinderTestCase.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/PropertyFinderTestCase.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,626 @@
+/*
+ * 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.directmemory.lightning;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import org.apache.directmemory.lightning.Lightning;
+import org.apache.directmemory.lightning.Serializer;
+import org.apache.directmemory.lightning.base.AbstractSerializerDefinition;
+import org.apache.directmemory.lightning.internal.ClassDescriptorAwareSerializer;
+import org.apache.directmemory.lightning.io.SerializerInputStream;
+import org.apache.directmemory.lightning.io.SerializerOutputStream;
+import org.apache.directmemory.lightning.metadata.Attribute;
+import org.apache.directmemory.lightning.metadata.ClassDescriptor;
+import org.junit.Test;
+
+public class PropertyFinderTestCase
+{
+
+ @Test
+ public void testCustomDefinedPropertyFind1()
+ throws Exception
+ {
+ Serializer serializer = Lightning.createSerializer( new AbstractSerializerDefinition()
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( Standard.class ).attributes( attribute( "value1" ) );
+ serialize( Standard.class ).attributes( attribute( "value2" ) );
+ }
+ } );
+
+ ClassDescriptorAwareSerializer awareSerializer = (ClassDescriptorAwareSerializer) serializer;
+ ClassDescriptor classDescriptor = awareSerializer.findClassDescriptor( Standard.class );
+
+ assertNotNull( classDescriptor );
+ assertEquals( 2, classDescriptor.getPropertyDescriptors().size() );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+
+ Standard standard = new Standard();
+ standard.setValue1( "Foo" );
+ standard.setValue2( 321 );
+ out.writeObject( standard );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+
+ Standard result = (Standard) in.readObject();
+
+ assertEquals( standard, result );
+ }
+
+ @Test
+ public void testCustomDefinedPropertyFind2()
+ throws Exception
+ {
+ Serializer serializer = Lightning.createSerializer( new AbstractSerializerDefinition()
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( Standard.class ).attributes( attribute( "value1" ), attribute( "value2" ) );
+ }
+ } );
+
+ ClassDescriptorAwareSerializer awareSerializer = (ClassDescriptorAwareSerializer) serializer;
+ ClassDescriptor classDescriptor = awareSerializer.findClassDescriptor( Standard.class );
+
+ assertNotNull( classDescriptor );
+ assertEquals( 2, classDescriptor.getPropertyDescriptors().size() );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+
+ Standard standard = new Standard();
+ standard.setValue1( "Foo" );
+ standard.setValue2( 321 );
+ out.writeObject( standard );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+
+ Standard result = (Standard) in.readObject();
+
+ assertEquals( standard, result );
+ }
+
+ @Test
+ public void testStandardPropertyFind()
+ throws Exception
+ {
+ Serializer serializer = Lightning.createSerializer( new AbstractSerializerDefinition()
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( Standard.class ).attributes();
+ }
+ } );
+
+ ClassDescriptorAwareSerializer awareSerializer = (ClassDescriptorAwareSerializer) serializer;
+ ClassDescriptor classDescriptor = awareSerializer.findClassDescriptor( Standard.class );
+
+ assertNotNull( classDescriptor );
+ assertEquals( 2, classDescriptor.getPropertyDescriptors().size() );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+
+ Standard standard = new Standard();
+ standard.setValue1( "Foo" );
+ standard.setValue2( 321 );
+ out.writeObject( standard );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+
+ Standard result = (Standard) in.readObject();
+
+ assertEquals( standard, result );
+ }
+
+ @Test
+ public void testStandardPropertyFindUsingExclude()
+ throws Exception
+ {
+ Serializer serializer = Lightning.createSerializer( new AbstractSerializerDefinition()
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( Standard.class ).attributes().exclude( "value1" );
+ }
+ } );
+
+ ClassDescriptorAwareSerializer awareSerializer = (ClassDescriptorAwareSerializer) serializer;
+ ClassDescriptor classDescriptor = awareSerializer.findClassDescriptor( Standard.class );
+
+ assertNotNull( classDescriptor );
+ assertEquals( 1, classDescriptor.getPropertyDescriptors().size() );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+
+ Standard standard = new Standard();
+ standard.setValue1( "Foo" );
+ standard.setValue2( 321 );
+ out.writeObject( standard );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+
+ Standard result = (Standard) in.readObject();
+
+ assertNull( "value1 must not be set", result.getValue1() );
+ assertEquals( standard.getValue2(), result.getValue2() );
+ }
+
+ @Test
+ public void testStandardPropertyFindUsingExcludes()
+ throws Exception
+ {
+ Serializer serializer = Lightning.createSerializer( new AbstractSerializerDefinition()
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( Inherted.class ).attributes().excludes( "value1", "value2" );
+ }
+ } );
+
+ ClassDescriptorAwareSerializer awareSerializer = (ClassDescriptorAwareSerializer) serializer;
+ ClassDescriptor classDescriptor = awareSerializer.findClassDescriptor( Inherted.class );
+
+ assertNotNull( classDescriptor );
+ assertEquals( 2, classDescriptor.getPropertyDescriptors().size() );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+
+ Inherted inherted = new Inherted();
+ inherted.setValue1( "Foo" );
+ inherted.setValue2( 321 );
+ inherted.setValue3( "Bar" );
+ inherted.setValue4( 123L );
+ out.writeObject( inherted );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+
+ Inherted result = (Inherted) in.readObject();
+
+ assertNull( "value1 must not be set", result.getValue1() );
+ assertEquals( result.getValue2(), 0 );
+ assertEquals( inherted.getValue3(), result.getValue3() );
+ assertEquals( inherted.getValue4(), result.getValue4() );
+ }
+
+ @Test
+ public void testInheritancePropertyFind()
+ throws Exception
+ {
+ Serializer serializer = Lightning.createSerializer( new AbstractSerializerDefinition()
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( Inherted.class ).attributes();
+ }
+ } );
+
+ ClassDescriptorAwareSerializer awareSerializer = (ClassDescriptorAwareSerializer) serializer;
+ ClassDescriptor classDescriptor = awareSerializer.findClassDescriptor( Inherted.class );
+
+ assertNotNull( classDescriptor );
+ assertEquals( 4, classDescriptor.getPropertyDescriptors().size() );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+
+ Inherted inherted = new Inherted();
+ inherted.setValue1( "Foo" );
+ inherted.setValue2( 321 );
+ inherted.setValue3( "Bar" );
+ inherted.setValue4( 123 );
+ out.writeObject( inherted );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+
+ Standard result = (Standard) in.readObject();
+
+ assertEquals( inherted, result );
+ }
+
+ @Test
+ public void testCompositionPropertyFind()
+ throws Exception
+ {
+ Serializer serializer = Lightning.createSerializer( new AbstractSerializerDefinition()
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( Composed.class ).attributes();
+ }
+ } );
+
+ ClassDescriptorAwareSerializer awareSerializer = (ClassDescriptorAwareSerializer) serializer;
+ ClassDescriptor classDescriptor = awareSerializer.findClassDescriptor( Composed.class );
+
+ assertNotNull( classDescriptor );
+ assertEquals( 3, classDescriptor.getPropertyDescriptors().size() );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+
+ Composed composed = new Composed( "Foo", 123, "Bar" );
+ out.writeObject( composed );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+
+ Composed result = (Composed) in.readObject();
+
+ assertEquals( composed, result );
+ }
+
+ @Test
+ public void testComposedInheritancePropertyFind()
+ throws Exception
+ {
+ Serializer serializer = Lightning.createSerializer( new AbstractSerializerDefinition()
+ {
+
+ @Override
+ protected void configure()
+ {
+ serialize( ComposedInherted.class ).attributes();
+ }
+ } );
+
+ ClassDescriptorAwareSerializer awareSerializer = (ClassDescriptorAwareSerializer) serializer;
+ ClassDescriptor classDescriptor = awareSerializer.findClassDescriptor( ComposedInherted.class );
+
+ assertNotNull( classDescriptor );
+ assertEquals( 3, classDescriptor.getPropertyDescriptors().size() );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+
+ ComposedInherted composedInherted = new ComposedInherted();
+ composedInherted.setValue1( "Foo" );
+ composedInherted.setValue2( 321 );
+ composedInherted.setValue3( "Bar" );
+ out.writeObject( composedInherted );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+
+ ComposedInherted result = (ComposedInherted) in.readObject();
+
+ assertEquals( composedInherted, result );
+ }
+
+ public static class Standard
+ {
+
+ @Attribute
+ private String value1;
+
+ @Attribute
+ private int value2;
+
+ public String getValue1()
+ {
+ return value1;
+ }
+
+ public void setValue1( String value1 )
+ {
+ this.value1 = value1;
+ }
+
+ public int getValue2()
+ {
+ return value2;
+ }
+
+ public void setValue2( int value2 )
+ {
+ this.value2 = value2;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ( ( value1 == null ) ? 0 : value1.hashCode() );
+ result = prime * result + value2;
+ return result;
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ return true;
+ if ( obj == null )
+ return false;
+ if ( getClass() != obj.getClass() )
+ return false;
+ Standard other = (Standard) obj;
+ if ( value1 == null )
+ {
+ if ( other.value1 != null )
+ return false;
+ }
+ else if ( !value1.equals( other.value1 ) )
+ return false;
+ if ( value2 != other.value2 )
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Standard [value1=" + value1 + ", value2=" + value2 + "]";
+ }
+ }
+
+ public static class Inherted
+ extends Standard
+ {
+
+ @Attribute
+ private String value3;
+
+ @Attribute
+ private long value4;
+
+ public String getValue3()
+ {
+ return value3;
+ }
+
+ public void setValue3( String value3 )
+ {
+ this.value3 = value3;
+ }
+
+ public long getValue4()
+ {
+ return value4;
+ }
+
+ public void setValue4( long value4 )
+ {
+ this.value4 = value4;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ( ( value3 == null ) ? 0 : value3.hashCode() );
+ result = prime * result + (int) ( value4 ^ ( value4 >>> 32 ) );
+ return result;
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ return true;
+ if ( !super.equals( obj ) )
+ return false;
+ if ( getClass() != obj.getClass() )
+ return false;
+ Inherted other = (Inherted) obj;
+ if ( value3 == null )
+ {
+ if ( other.value3 != null )
+ return false;
+ }
+ else if ( !value3.equals( other.value3 ) )
+ return false;
+ if ( value4 != other.value4 )
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Inherted [value3=" + value3 + ", value4=" + value4 + "]";
+ }
+ }
+
+ public static class ComposedInherted
+ extends Standard
+ implements Foo, Bar
+ {
+
+ private String value3;
+
+ public void setValue3( String value3 )
+ {
+ this.value3 = value3;
+ }
+
+ @Override
+ public String getValue3()
+ {
+ return value3;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ( ( value3 == null ) ? 0 : value3.hashCode() );
+ return result;
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ return true;
+ if ( !super.equals( obj ) )
+ return false;
+ if ( getClass() != obj.getClass() )
+ return false;
+ ComposedInherted other = (ComposedInherted) obj;
+ if ( value3 == null )
+ {
+ if ( other.value3 != null )
+ return false;
+ }
+ else if ( !value3.equals( other.value3 ) )
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ComposedInherted [value3=" + value3 + "]";
+ }
+ }
+
+ public static interface Foo
+ {
+
+ @Attribute
+ String getValue1();
+
+ @Attribute
+ int getValue2();
+ }
+
+ public static interface Bar
+ {
+
+ @Attribute
+ String getValue3();
+ }
+
+ public static class Composed
+ implements Foo, Bar
+ {
+
+ private final String value1;
+
+ private final int value2;
+
+ private final String value3;
+
+ public Composed( String value1, int value2, String value3 )
+ {
+ this.value1 = value1;
+ this.value2 = value2;
+ this.value3 = value3;
+ }
+
+ @Override
+ public String getValue3()
+ {
+ return value3;
+ }
+
+ @Override
+ public String getValue1()
+ {
+ return value1;
+ }
+
+ @Override
+ public int getValue2()
+ {
+ return value2;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ( ( value1 == null ) ? 0 : value1.hashCode() );
+ result = prime * result + value2;
+ result = prime * result + ( ( value3 == null ) ? 0 : value3.hashCode() );
+ return result;
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ return true;
+ if ( obj == null )
+ return false;
+ if ( getClass() != obj.getClass() )
+ return false;
+ Composed other = (Composed) obj;
+ if ( value1 == null )
+ {
+ if ( other.value1 != null )
+ return false;
+ }
+ else if ( !value1.equals( other.value1 ) )
+ return false;
+ if ( value2 != other.value2 )
+ return false;
+ if ( value3 == null )
+ {
+ if ( other.value3 != null )
+ return false;
+ }
+ else if ( !value3.equals( other.value3 ) )
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Composed [value1=" + value1 + ", value2=" + value2 + ", value3=" + value3 + "]";
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/PropertyFinderTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/PropertyFinderTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/WhatShouldItLookLike.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/WhatShouldItLookLike.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/WhatShouldItLookLike.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/WhatShouldItLookLike.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,300 @@
+/*
+ * 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.directmemory.lightning;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directmemory.lightning.Lightning;
+import org.apache.directmemory.lightning.MarshallerContext;
+import org.apache.directmemory.lightning.MarshallerStrategy;
+import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.Serializer;
+import org.apache.directmemory.lightning.base.AbstractObjectMarshaller;
+import org.apache.directmemory.lightning.base.AbstractSerializerDefinition;
+import org.apache.directmemory.lightning.configuration.TypeIntrospector;
+import org.apache.directmemory.lightning.generator.PropertyDescriptorFactory;
+import org.apache.directmemory.lightning.internal.util.DebugLogger;
+import org.apache.directmemory.lightning.io.SerializerInputStream;
+import org.apache.directmemory.lightning.io.SerializerOutputStream;
+import org.apache.directmemory.lightning.metadata.ClassDefinitionContainer;
+import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
+
+public class WhatShouldItLookLike
+{
+
+ public static void main( String[] args )
+ {
+ Serializer serializer2 =
+ Lightning.newBuilder().logger( new DebugLogger() ).serializerDefinitions( new ExampleSerializerDefinition() ).build();
+
+ ClassDefinitionContainer container2 = serializer2.getClassDefinitionContainer();
+
+ Serializer remoteSerializer2 =
+ Lightning.newBuilder().logger( new DebugLogger() ).serializerDefinitions( new ExampleSerializerDefinition() ).build();
+
+ remoteSerializer2.setClassDefinitionContainer( container2 );
+
+ Serializer serializer = Lightning.createSerializer( new ExampleSerializerDefinition() );
+ ClassDefinitionContainer container = serializer.getClassDefinitionContainer();
+
+ Serializer remoteSerializer = Lightning.createSerializer( new ExampleSerializerDefinition() );
+ remoteSerializer.setClassDefinitionContainer( container );
+
+ Foo foo = new Foo();
+ foo.enumValue = Bar.Value2;
+ foo.first = "first";
+ foo.second = "second";
+ foo.someOther = 123;
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializerOutputStream out = new SerializerOutputStream( baos, serializer );
+ out.writeObject( foo );
+ System.out.println( foo );
+
+ byte[] data = baos.toByteArray();
+ System.out.println( Arrays.toString( data ) );
+
+ ByteArrayInputStream bais = new ByteArrayInputStream( data );
+ SerializerInputStream in = new SerializerInputStream( bais, serializer );
+ Object value = in.readObject();
+ System.out.println( value );
+ }
+
+ public static class ExampleSerializerDefinition
+ extends AbstractSerializerDefinition
+ {
+
+ @Override
+ protected void configure()
+ {
+ // Define serializable class using custom implementation of
+ // Marshaller
+ serialize( Bar.class ).using( new BarMarshaller() );
+ serialize( Bar.class ).using( BarMarshaller.class );
+
+ // Define serializable class using annotated members / methods (by
+ // usage of Lightning's @org.apache.directmemory.lightning.metadata.Attribute
+ // annotation)
+ serialize( Foo.class ).attributes();
+ serialize( Foo.class ).attributes().exclude( "value" );
+ serialize( Foo.class ).attributes().exclude( "value1" ).exclude( "value2" );
+ serialize( Foo.class ).attributes().excludes( "value1", "value2" );
+
+ // Define serializable class using annotated members / methods (by
+ // usage of custom annotation)
+ serialize( Foo.class ).attributes( Attribute.class );
+ serialize( Foo.class ).attributes( Attribute.class ).exclude( "value" );
+ serialize( Foo.class ).attributes( Attribute.class ).exclude( "value1" ).exclude( "value2" );
+ serialize( Foo.class ).attributes( Attribute.class ).excludes( "value1", "value2" );
+
+ // Define serializable class using custom definition of attributes
+ serialize( Foo.class ).attributes( attribute( "value" ),
+ attribute( "value" ).using( SomeSpecialIntegerMarshaller.class ),
+ attribute( "value" ).using( new SomeSpecialIntegerMarshaller() ) );
+
+ // Define serializable class using a different implementation of
+ // PropertyFinderStrategy
+ serialize( Foo.class ).using( new FooTypeIntrospector() );
+ serialize( Foo.class ).using( FooTypeIntrospector.class );
+
+ // Install child definition
+ install( new SomeChildSerializerDefinition() );
+ }
+ }
+
+ public static class SomeChildSerializerDefinition
+ extends AbstractSerializerDefinition
+ {
+
+ @Override
+ public void configure()
+ {
+ describesAttributes( Attribute.class );
+
+ serialize( Foo.class ).attributes();
+ }
+ }
+
+ public static class FooTypeIntrospector
+ implements TypeIntrospector
+ {
+
+ @Override
+ public List<PropertyDescriptor> introspect( Type type, MarshallerStrategy marshallerStrategy,
+ MarshallerContext marshallerContext,
+ PropertyDescriptorFactory propertyDescriptorFactory )
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ }
+
+ public static class Foo
+ {
+
+ private String first;
+
+ private String second;
+
+ private Integer value;
+
+ private int someOther;
+
+ @Attribute
+ private Bar enumValue;
+
+ @Attribute( required = true )
+ public String getFirst()
+ {
+ return first;
+ }
+
+ public void setFirst( String first )
+ {
+ this.first = first;
+ }
+
+ @Attribute
+ public String getSecond()
+ {
+ return second;
+ }
+
+ public void setSecond( String second )
+ {
+ this.second = second;
+ }
+
+ @Attribute
+ public Integer getValue()
+ {
+ return value;
+ }
+
+ public void setValue( Integer value )
+ {
+ this.value = value;
+ }
+
+ @Attribute
+ // Implicitly required
+ public int getSomeOther()
+ {
+ return someOther;
+ }
+
+ public void setSomeOther( int someOther )
+ {
+ this.someOther = someOther;
+ }
+
+ public Bar getEnumValue()
+ {
+ return enumValue;
+ }
+
+ public void setEnumValue( Bar enumValue )
+ {
+ this.enumValue = enumValue;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Foo [hash=@" + hashCode() + ", first=" + first + ", second=" + second + ", value=" + value
+ + ", someOther=" + someOther + ", enumValue=" + enumValue + "]";
+ }
+ }
+
+ public static enum Bar
+ {
+ Value1, Value2
+ }
+
+ @Retention( RetentionPolicy.RUNTIME )
+ public static @interface Attribute
+ {
+
+ boolean required() default false;
+ }
+
+ public static class BarMarshaller
+ extends AbstractObjectMarshaller
+ {
+
+ @Override
+ public boolean acceptType( Class<?> type )
+ {
+ return type == Bar.class;
+ }
+
+ @Override
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+ }
+
+ @Override
+ public <V> V unmarshall( V value, PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+
+ return null;
+ }
+ }
+
+ public static class SomeSpecialIntegerMarshaller
+ extends AbstractObjectMarshaller
+ {
+
+ @Override
+ public boolean acceptType( Class<?> type )
+ {
+ return type == Integer.class;
+ }
+
+ @Override
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+ }
+
+ @Override
+ public <V> V unmarshall( V value, PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+
+ return value;
+ }
+
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/WhatShouldItLookLike.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/WhatShouldItLookLike.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/ClassDefinitionContainerTestCase.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/ClassDefinitionContainerTestCase.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/ClassDefinitionContainerTestCase.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/ClassDefinitionContainerTestCase.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,59 @@
+/*
+ * 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.directmemory.lightning.internal;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directmemory.lightning.internal.InternalClassDefinition;
+import org.apache.directmemory.lightning.internal.InternalClassDefinitionContainer;
+import org.apache.directmemory.lightning.logging.LoggerAdapter;
+import org.apache.directmemory.lightning.metadata.ClassDefinition;
+import org.apache.directmemory.lightning.metadata.ClassDefinitionContainer;
+import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
+import org.junit.Test;
+import org.objectweb.asm.ClassVisitor;
+
+public class ClassDefinitionContainerTestCase
+{
+
+ private static final Class<?>[] CLASSES = { ClassVisitor.class };
+
+ @Test
+ public void testClassDefinitionContainer()
+ throws Exception
+ {
+ final Set<ClassDefinition> classDefinitions = new HashSet<ClassDefinition>();
+
+ for ( Class<?> clazz : CLASSES )
+ {
+ PropertyDescriptor label = null;
+ classDefinitions.add( new InternalClassDefinition( clazz, Collections.<PropertyDescriptor> emptyList(),
+ new LoggerAdapter() ) );
+ }
+
+ ClassDefinitionContainer classDefinitionContainer = new InternalClassDefinitionContainer( classDefinitions );
+
+ for ( ClassDefinition classDefinition : classDefinitionContainer.getClassDefinitions() )
+ {
+ Class<?> clazz = null;
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/ClassDefinitionContainerTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/ClassDefinitionContainerTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/beans/ReflectionPropertyAccessorTestCase.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/beans/ReflectionPropertyAccessorTestCase.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/beans/ReflectionPropertyAccessorTestCase.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/beans/ReflectionPropertyAccessorTestCase.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,270 @@
+/*
+ * 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.directmemory.lightning.internal.beans;
+
+import java.lang.reflect.Field;
+import java.util.Arrays;
+
+import org.apache.directmemory.lightning.internal.beans.ReflectionPropertyAccessorFactory;
+import org.apache.directmemory.lightning.metadata.ArrayPropertyAccessor;
+import org.junit.Test;
+
+public class ReflectionPropertyAccessorTestCase
+{
+
+ @Test
+ public void testUnsafeBooleanArray()
+ throws Exception
+ {
+ class BooleanArrayTest
+ {
+
+ private boolean[] array = new boolean[10];
+ }
+
+ Field field = BooleanArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new ReflectionPropertyAccessorFactory().fieldAccess( field, BooleanArrayTest.class );
+
+ BooleanArrayTest test = new BooleanArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = i % 2 == 0 ? true : false;
+ }
+
+ BooleanArrayTest result = new BooleanArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ boolean value = propertyAccessor.readBoolean( test.array, i );
+ propertyAccessor.writeBoolean( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeByteArray()
+ throws Exception
+ {
+ class ByteArrayTest
+ {
+
+ private byte[] array = new byte[10];
+ }
+
+ Field field = ByteArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new ReflectionPropertyAccessorFactory().fieldAccess( field, ByteArrayTest.class );
+
+ ByteArrayTest test = new ByteArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = (byte) ( i + 1 );
+ }
+
+ ByteArrayTest result = new ByteArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ byte value = propertyAccessor.readByte( test.array, i );
+ propertyAccessor.writeByte( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeShortArray()
+ throws Exception
+ {
+ class ShortArrayTest
+ {
+
+ private short[] array = new short[10];
+ }
+
+ Field field = ShortArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new ReflectionPropertyAccessorFactory().fieldAccess( field, ShortArrayTest.class );
+
+ ShortArrayTest test = new ShortArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = (short) ( i + 1 );
+ }
+
+ ShortArrayTest result = new ShortArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ short value = propertyAccessor.readShort( test.array, i );
+ propertyAccessor.writeShort( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeIntArray()
+ throws Exception
+ {
+ class IntArrayTest
+ {
+
+ private int[] array = new int[10];
+ }
+
+ Field field = IntArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new ReflectionPropertyAccessorFactory().fieldAccess( field, IntArrayTest.class );
+
+ IntArrayTest test = new IntArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = i + 1;
+ }
+
+ IntArrayTest result = new IntArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ int value = propertyAccessor.readInt( test.array, i );
+ propertyAccessor.writeInt( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeLongArray()
+ throws Exception
+ {
+ class LongArrayTest
+ {
+
+ private long[] array = new long[10];
+ }
+
+ Field field = LongArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new ReflectionPropertyAccessorFactory().fieldAccess( field, LongArrayTest.class );
+
+ LongArrayTest test = new LongArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = i + 1;
+ }
+
+ LongArrayTest result = new LongArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ long value = propertyAccessor.readLong( test.array, i );
+ propertyAccessor.writeLong( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeFloatArray()
+ throws Exception
+ {
+ class FloatArrayTest
+ {
+
+ private float[] array = new float[10];
+ }
+
+ Field field = FloatArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new ReflectionPropertyAccessorFactory().fieldAccess( field, FloatArrayTest.class );
+
+ FloatArrayTest test = new FloatArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = (float) ( i + 1. );
+ }
+
+ FloatArrayTest result = new FloatArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ float value = propertyAccessor.readFloat( test.array, i );
+ propertyAccessor.writeFloat( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeDoubleArray()
+ throws Exception
+ {
+ class DoubleArrayTest
+ {
+
+ private double[] array = new double[10];
+ }
+
+ Field field = DoubleArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new ReflectionPropertyAccessorFactory().fieldAccess( field, DoubleArrayTest.class );
+
+ DoubleArrayTest test = new DoubleArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = i + 1.;
+ }
+
+ DoubleArrayTest result = new DoubleArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ double value = propertyAccessor.readDouble( test.array, i );
+ propertyAccessor.writeDouble( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeObjectArray()
+ throws Exception
+ {
+ class ObjectArrayTest
+ {
+
+ private String[] array = new String[10];
+ }
+
+ Field field = ObjectArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new ReflectionPropertyAccessorFactory().fieldAccess( field, ObjectArrayTest.class );
+
+ ObjectArrayTest test = new ObjectArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = "Hello" + i;
+ }
+
+ ObjectArrayTest result = new ObjectArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ Object value = propertyAccessor.readObject( test.array, i );
+ propertyAccessor.writeObject( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/beans/ReflectionPropertyAccessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/beans/ReflectionPropertyAccessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/beans/UnsafePropertyAccessorTestCase.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/beans/UnsafePropertyAccessorTestCase.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/beans/UnsafePropertyAccessorTestCase.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/beans/UnsafePropertyAccessorTestCase.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,270 @@
+/*
+ * 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.directmemory.lightning.internal.beans;
+
+import java.lang.reflect.Field;
+import java.util.Arrays;
+
+import org.apache.directmemory.lightning.internal.beans.SunUnsafePropertyAccessorFactory;
+import org.apache.directmemory.lightning.metadata.ArrayPropertyAccessor;
+import org.junit.Test;
+
+public class UnsafePropertyAccessorTestCase
+{
+
+ @Test
+ public void testUnsafeBooleanArray()
+ throws Exception
+ {
+ class BooleanArrayTest
+ {
+
+ private boolean[] array = new boolean[10];
+ }
+
+ Field field = BooleanArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new SunUnsafePropertyAccessorFactory().fieldAccess( field, BooleanArrayTest.class );
+
+ BooleanArrayTest test = new BooleanArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = i % 2 == 0 ? true : false;
+ }
+
+ BooleanArrayTest result = new BooleanArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ boolean value = propertyAccessor.readBoolean( test.array, i );
+ propertyAccessor.writeBoolean( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeByteArray()
+ throws Exception
+ {
+ class ByteArrayTest
+ {
+
+ private byte[] array = new byte[10];
+ }
+
+ Field field = ByteArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new SunUnsafePropertyAccessorFactory().fieldAccess( field, ByteArrayTest.class );
+
+ ByteArrayTest test = new ByteArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = (byte) ( i + 1 );
+ }
+
+ ByteArrayTest result = new ByteArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ byte value = propertyAccessor.readByte( test.array, i );
+ propertyAccessor.writeByte( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeShortArray()
+ throws Exception
+ {
+ class ShortArrayTest
+ {
+
+ private short[] array = new short[10];
+ }
+
+ Field field = ShortArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new SunUnsafePropertyAccessorFactory().fieldAccess( field, ShortArrayTest.class );
+
+ ShortArrayTest test = new ShortArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = (short) ( i + 1 );
+ }
+
+ ShortArrayTest result = new ShortArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ short value = propertyAccessor.readShort( test.array, i );
+ propertyAccessor.writeShort( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeIntArray()
+ throws Exception
+ {
+ class IntArrayTest
+ {
+
+ private int[] array = new int[10];
+ }
+
+ Field field = IntArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new SunUnsafePropertyAccessorFactory().fieldAccess( field, IntArrayTest.class );
+
+ IntArrayTest test = new IntArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = i + 1;
+ }
+
+ IntArrayTest result = new IntArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ int value = propertyAccessor.readInt( test.array, i );
+ propertyAccessor.writeInt( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeLongArray()
+ throws Exception
+ {
+ class LongArrayTest
+ {
+
+ private long[] array = new long[10];
+ }
+
+ Field field = LongArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new SunUnsafePropertyAccessorFactory().fieldAccess( field, LongArrayTest.class );
+
+ LongArrayTest test = new LongArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = i + 1;
+ }
+
+ LongArrayTest result = new LongArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ long value = propertyAccessor.readLong( test.array, i );
+ propertyAccessor.writeLong( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeFloatArray()
+ throws Exception
+ {
+ class FloatArrayTest
+ {
+
+ private float[] array = new float[10];
+ }
+
+ Field field = FloatArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new SunUnsafePropertyAccessorFactory().fieldAccess( field, FloatArrayTest.class );
+
+ FloatArrayTest test = new FloatArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = (float) ( i + 1. );
+ }
+
+ FloatArrayTest result = new FloatArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ float value = propertyAccessor.readFloat( test.array, i );
+ propertyAccessor.writeFloat( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeDoubleArray()
+ throws Exception
+ {
+ class DoubleArrayTest
+ {
+
+ private double[] array = new double[10];
+ }
+
+ Field field = DoubleArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new SunUnsafePropertyAccessorFactory().fieldAccess( field, DoubleArrayTest.class );
+
+ DoubleArrayTest test = new DoubleArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = i + 1.;
+ }
+
+ DoubleArrayTest result = new DoubleArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ double value = propertyAccessor.readDouble( test.array, i );
+ propertyAccessor.writeDouble( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+
+ @Test
+ public void testUnsafeObjectArray()
+ throws Exception
+ {
+ class ObjectArrayTest
+ {
+
+ private String[] array = new String[10];
+ }
+
+ Field field = ObjectArrayTest.class.getDeclaredField( "array" );
+ ArrayPropertyAccessor propertyAccessor =
+ (ArrayPropertyAccessor) new SunUnsafePropertyAccessorFactory().fieldAccess( field, ObjectArrayTest.class );
+
+ ObjectArrayTest test = new ObjectArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ test.array[i] = "Hello" + i;
+ }
+
+ ObjectArrayTest result = new ObjectArrayTest();
+ for ( int i = 0; i < 10; i++ )
+ {
+ Object value = propertyAccessor.readObject( test.array, i );
+ propertyAccessor.writeObject( result.array, i, value );
+ }
+
+ Arrays.equals( test.array, result.array );
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/beans/UnsafePropertyAccessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/internal/beans/UnsafePropertyAccessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision