You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by br...@apache.org on 2010/03/27 00:38:24 UTC

svn commit: r928101 - in /incubator/thrift/trunk/lib/java: ./ test/org/apache/thrift/ test/org/apache/thrift/server/ test/org/apache/thrift/test/ test/org/apache/thrift/transport/

Author: bryanduxbury
Date: Fri Mar 26 23:38:23 2010
New Revision: 928101

URL: http://svn.apache.org/viewvc?rev=928101&view=rev
Log:
java: convert PartialDeserializeTest to testcase of TestTDeserializer (new junit test); add apache header to a few of the new test files.

Added:
    incubator/thrift/trunk/lib/java/test/org/apache/thrift/TestTDeserializer.java
Removed:
    incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/PartialDeserializeTest.java
Modified:
    incubator/thrift/trunk/lib/java/build.xml
    incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/ServerTestBase.java
    incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/TestHsHaServer.java
    incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/TestNonblockingServer.java
    incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/ReadCountingTransport.java
    incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/TestTFramedTransport.java
    incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/WriteCountingTransport.java

Modified: incubator/thrift/trunk/lib/java/build.xml
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/build.xml?rev=928101&r1=928100&r2=928101&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/build.xml (original)
+++ incubator/thrift/trunk/lib/java/build.xml Fri Mar 26 23:38:23 2010
@@ -207,8 +207,6 @@
       classpathref="test.classpath" failonerror="true" />
     <java classname="org.apache.thrift.test.UnionTest"
       classpathref="test.classpath" failonerror="true" />
-    <java classname="org.apache.thrift.test.PartialDeserializeTest"
-      classpathref="test.classpath" failonerror="true" />
   </target>
 
   <target name="test" description="Run the full test suite" depends="junit-test,deprecated-test"/>

Added: incubator/thrift/trunk/lib/java/test/org/apache/thrift/TestTDeserializer.java
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/TestTDeserializer.java?rev=928101&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/java/test/org/apache/thrift/TestTDeserializer.java (added)
+++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/TestTDeserializer.java Fri Mar 26 23:38:23 2010
@@ -0,0 +1,83 @@
+/*
+ * 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.thrift;
+
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.apache.thrift.protocol.TCompactProtocol;
+import org.apache.thrift.protocol.TJSONProtocol;
+import org.apache.thrift.protocol.TProtocolFactory;
+import org.apache.thrift.test.Fixtures;
+
+import thrift.test.Backwards;
+import thrift.test.OneOfEach;
+import thrift.test.PrimitiveThenStruct;
+import thrift.test.StructWithAUnion;
+import thrift.test.TestUnion;
+
+import junit.framework.TestCase;
+
+public class TestTDeserializer extends TestCase {
+
+  private static final TProtocolFactory[] PROTOCOLS = new TProtocolFactory[] {
+    new TBinaryProtocol.Factory(), 
+    new TCompactProtocol.Factory(), 
+    new TJSONProtocol.Factory()
+  };
+
+  public void testPartialDeserialize() throws Exception {
+    //Root:StructWithAUnion
+    //  1:Union
+    //    1.3:OneOfEach
+    OneOfEach Level3OneOfEach = Fixtures.oneOfEach;
+    TestUnion Level2TestUnion = new TestUnion(TestUnion._Fields.STRUCT_FIELD, Level3OneOfEach);
+    StructWithAUnion Level1SWU = new StructWithAUnion(Level2TestUnion);
+
+    Backwards bw = new Backwards(2, 1);
+    PrimitiveThenStruct pts = new PrimitiveThenStruct(12345, 67890, bw);
+
+    for (TProtocolFactory factory : PROTOCOLS) {
+      //Full deserialization test
+      testPartialDeserialize(factory, Level1SWU, new StructWithAUnion(), Level1SWU);
+
+      //Level 2 test
+      testPartialDeserialize(factory, Level1SWU, new TestUnion(), Level2TestUnion, StructWithAUnion._Fields.TEST_UNION);
+
+      //Level 3 on 3rd field test
+      testPartialDeserialize(factory, Level1SWU, new OneOfEach(), Level3OneOfEach, StructWithAUnion._Fields.TEST_UNION, TestUnion._Fields.STRUCT_FIELD);
+
+      //Test early termination when traversed path Field.id exceeds the one being searched for
+      testPartialDeserialize(factory, Level1SWU, new OneOfEach(), new OneOfEach(), StructWithAUnion._Fields.TEST_UNION, TestUnion._Fields.I32_FIELD);
+
+      //Test that readStructBegin isn't called on primitive
+      testPartialDeserialize(factory, pts, new Backwards(), bw, PrimitiveThenStruct._Fields.BW);
+    }
+  }
+
+  public static void testPartialDeserialize(TProtocolFactory protocolFactory, TBase input, TBase output, TBase expected, TFieldIdEnum ... fieldIdPath) throws TException {
+    byte[] record = new TSerializer(protocolFactory).serialize(input);
+    TDeserializer deserializer = new TDeserializer(protocolFactory);
+    for (int i = 0; i < 2; i++) {
+      TBase outputCopy = output.deepCopy();
+      deserializer.partialDeserialize(outputCopy, record, fieldIdPath);
+      assertEquals("on attempt " + i + ", with " + protocolFactory.toString() 
+          + ", expected " + expected + " but got " + outputCopy,
+          expected, outputCopy);
+    }
+  }
+}

Modified: incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/ServerTestBase.java
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/ServerTestBase.java?rev=928101&r1=928100&r2=928101&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/ServerTestBase.java (original)
+++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/ServerTestBase.java Fri Mar 26 23:38:23 2010
@@ -1,3 +1,21 @@
+/*
+ * 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.thrift.server;
 
 import java.util.ArrayList;

Modified: incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/TestHsHaServer.java
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/TestHsHaServer.java?rev=928101&r1=928100&r2=928101&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/TestHsHaServer.java (original)
+++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/TestHsHaServer.java Fri Mar 26 23:38:23 2010
@@ -1,3 +1,21 @@
+/*
+ * 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.thrift.server;
 
 import org.apache.thrift.TProcessor;

Modified: incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/TestNonblockingServer.java
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/TestNonblockingServer.java?rev=928101&r1=928100&r2=928101&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/TestNonblockingServer.java (original)
+++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/TestNonblockingServer.java Fri Mar 26 23:38:23 2010
@@ -1,3 +1,21 @@
+/*
+ * 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.thrift.server;
 
 

Modified: incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/ReadCountingTransport.java
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/ReadCountingTransport.java?rev=928101&r1=928100&r2=928101&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/ReadCountingTransport.java (original)
+++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/ReadCountingTransport.java Fri Mar 26 23:38:23 2010
@@ -1,5 +1,20 @@
-/**
- * 
+/*
+ * 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.thrift.transport;
 

Modified: incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/TestTFramedTransport.java
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/TestTFramedTransport.java?rev=928101&r1=928100&r2=928101&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/TestTFramedTransport.java (original)
+++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/TestTFramedTransport.java Fri Mar 26 23:38:23 2010
@@ -1,3 +1,21 @@
+/*
+ * 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.thrift.transport;
 
 import java.io.ByteArrayInputStream;

Modified: incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/WriteCountingTransport.java
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/WriteCountingTransport.java?rev=928101&r1=928100&r2=928101&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/WriteCountingTransport.java (original)
+++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/transport/WriteCountingTransport.java Fri Mar 26 23:38:23 2010
@@ -1,4 +1,21 @@
-
+/*
+ * 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.thrift.transport;
 
 import org.apache.thrift.transport.TTransport;