You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by th...@apache.org on 2012/07/12 20:17:44 UTC

svn commit: r1360842 - in /avro/trunk: CHANGES.txt lang/csharp/src/apache/main/Specific/ObjectCreator.cs lang/csharp/src/apache/test/Specific/SpecificTests.cs

Author: thiru
Date: Thu Jul 12 18:17:44 2012
New Revision: 1360842

URL: http://svn.apache.org/viewvc?rev=1360842&view=rev
Log:
AVRO-1109. CSharp specific fails on multidimensional arrays.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
    avro/trunk/lang/csharp/src/apache/test/Specific/SpecificTests.cs

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1360842&r1=1360841&r2=1360842&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu Jul 12 18:17:44 2012
@@ -38,6 +38,8 @@ Avro 1.7.1 (unreleased)
 
     AVRO-1116. C++ code crashes on Data files with no data. (thiru)
 
+    AVRO-1109. CSharp specific fails on multidimensional arrays. (Mark Farnan via thiru)
+
 Avro 1.7.0 (11 June 2012)
 
   NEW FEATURES

Modified: avro/trunk/lang/csharp/src/apache/main/Specific/ObjectCreator.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/main/Specific/ObjectCreator.cs?rev=1360842&r1=1360841&r2=1360842&view=diff
==============================================================================
--- avro/trunk/lang/csharp/src/apache/main/Specific/ObjectCreator.cs (original)
+++ avro/trunk/lang/csharp/src/apache/main/Specific/ObjectCreator.cs Thu Jul 12 18:17:44 2012
@@ -112,6 +112,15 @@ namespace Avro.Specific
         public Type GetType(string name, Schema.Type schemaType)
         {
             Type type;
+
+            // Modify provided type to ensure it can be discovered.
+            // This is mainly for Generics, and Nullables.
+
+            name = name.Replace("Nullable", "Nullable`1");
+            name = name.Replace("IList", "System.Collections.Generic.IList`1");
+            name = name.Replace("<", "[");
+            name = name.Replace(">", "]");
+
             if (diffAssembly)
             {
                 // entry assembly different from current assembly, try entry assembly first
@@ -122,12 +131,23 @@ namespace Avro.Specific
             else
                 type = Type.GetType(name);
 
+            Type[] types;
+
             if (type == null) // type is still not found, need to loop through all loaded assemblies
             {
                 Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
                 foreach (Assembly assembly in assemblies)
                 {
-                    type = assembly.GetType(name);
+                    types = assembly.GetTypes();
+
+                    // Change the search to look for Types by both NAME and FULLNAME
+                    foreach (Type t in types)
+                    {
+                        if (name == t.Name || name == t.FullName) type = t;
+
+                    }
+
+                    
                     if (type != null)
                         break;
                 }

Modified: avro/trunk/lang/csharp/src/apache/test/Specific/SpecificTests.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/test/Specific/SpecificTests.cs?rev=1360842&r1=1360841&r2=1360842&view=diff
==============================================================================
--- avro/trunk/lang/csharp/src/apache/test/Specific/SpecificTests.cs (original)
+++ avro/trunk/lang/csharp/src/apache/test/Specific/SpecificTests.cs Thu Jul 12 18:17:44 2012
@@ -81,15 +81,17 @@ namespace Avro.Test
 				{ ""name"" : ""myArray2"", ""type"" : { ""type"" : ""array"", ""items"" : { ""type"" : ""record"", ""name"" : ""newRec"", ""fields"" : [ { ""name"" : ""f1"", ""type"" : ""long""} ] } } },
 				{ ""name"" : ""myMap"", ""type"" : { ""type"" : ""map"", ""values"" : ""string"" } },
 				{ ""name"" : ""myMap2"", ""type"" : { ""type"" : ""map"", ""values"" : ""newRec"" } },
-				{ ""name"" : ""myObject"", ""type"" : [ ""MyEnum"", ""A"", ""null"" ] }
+				{ ""name"" : ""myObject"", ""type"" : [ ""MyEnum"", ""A"", ""null"" ] },
+                { ""name"" : ""myArray3"", ""type"" : { ""type"" : ""array"", ""items"" : { ""type"" : ""array"", ""items"" : [ ""double"", ""string"", ""null"" ] } } }
 			]
    } 
    ]
 }"
 , new object[] {3, // index of the schema to serialize
   "com.foo.Z",  // name of the schema to serialize
+@"Console.WriteLine(""Constructing com.foo.Z..."");", // Empty Constructor.
 @"
-  Console.WriteLine(""Constructing com.foo.Z..."");
+  Console.WriteLine(""Populating com.foo.Z..."");
   string bytes = ""bytes sample text"";
   System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
 
@@ -130,6 +132,26 @@ namespace Avro.Test
   newrec.f1 = 1200;
   myMap2.Add(""A"", newrec);
   myObject = com.foo.MyEnum.B;
+
+  IList<System.Object> o1 = new List<System.Object>();
+
+    o1.Add((double)1123123121);
+    o1.Add((double)2);
+    o1.Add(null);
+    o1.Add(""fred"");
+
+    IList<System.Object> o2 = new List<System.Object>();
+
+    o2.Add((double)1);
+    o2.Add((double)32531);
+    o2.Add((double)4);
+    o2.Add((double)555);
+    o2.Add((double)0);
+
+    myArray3 = new List<IList<System.Object>>();
+    myArray3.Add(o1);
+    myArray3.Add(o2);
+
 "}
 )]
         public static void TestSpecific(string str, object[] result)
@@ -147,6 +169,18 @@ namespace Avro.Test
             constructor.Statements.Add(snippet);
             ctd.Members.Add(constructor);
 
+            // add a function to the main class to populate the data
+            // This has been moved from constructor, as it was causing some tests to pass that shouldn't when referencing a blank object on READ.
+
+            CodeMemberMethod method = new CodeMemberMethod();
+            method.Attributes = MemberAttributes.Public;
+            method.Name = "Populate";
+            CodeSnippetExpression snippet2 = new CodeSnippetExpression((string)result[3]);
+            method.Statements.Add(snippet2);
+            ctd.Members.Add(method);
+
+
+
             // compile
             var comparam = new CompilerParameters(new string[] { "mscorlib.dll" });
             comparam.ReferencedAssemblies.Add("System.dll");
@@ -167,6 +201,15 @@ namespace Avro.Test
 
             // create record
             ISpecificRecord rec = compres.CompiledAssembly.CreateInstance((string)result[1]) as ISpecificRecord;
+
+            // Call populate to put some data in it.
+            Type recType = rec.GetType(); ;
+            MethodInfo methodInfo = recType.GetMethod("Populate");
+            methodInfo.Invoke(rec, null);
+
+            var x1 = compres.CompiledAssembly.FullName;
+            
+
             Assert.IsFalse(rec == null);
 
             // serialize