Author: cutting
Date: Wed Dec 7 22:36:53 2011
New Revision: 1211683
URL: http://svn.apache.org/viewvc?rev=1211683&view=rev
Log:
AVRO-835. C#: Fix codgen for protocols to not fail. Contributed by Dona Alvarez.
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/csharp/src/apache/main/Protocol/Message.cs
avro/trunk/lang/csharp/src/apache/main/Schema/NamedSchema.cs
avro/trunk/lang/csharp/src/apache/main/Schema/RecordSchema.cs
avro/trunk/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs
Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1211683&r1=1211682&r2=1211683&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed Dec 7 22:36:53 2011
@@ -16,6 +16,9 @@ Avro 1.6.2 (unreleased)
AVRO-962. Java: Fix Maven plugin to support string type override.
(George Fletcher via cutting)
+ AVRO-835. C#: Fix codgen for protocols to not fail.
+ (Dona Alvarez via cutting)
+
Avro 1.6.1 (8 November 2011)
INCOMPATIBLE CHANGES
Modified: avro/trunk/lang/csharp/src/apache/main/Protocol/Message.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/main/Protocol/Message.cs?rev=1211683&r1=1211682&r2=1211683&view=diff
==============================================================================
--- avro/trunk/lang/csharp/src/apache/main/Protocol/Message.cs (original)
+++ avro/trunk/lang/csharp/src/apache/main/Protocol/Message.cs Wed Dec 7 22:36:53 2011
@@ -124,7 +124,7 @@ namespace Avro
if (null != this.Response)
{
writer.WritePropertyName("response");
- writer.WriteValue(Response.Name);
+ Response.WriteJson(writer, names, encspace);
}
if (null != this.Error)
Modified: avro/trunk/lang/csharp/src/apache/main/Schema/NamedSchema.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/main/Schema/NamedSchema.cs?rev=1211683&r1=1211682&r2=1211683&view=diff
==============================================================================
--- avro/trunk/lang/csharp/src/apache/main/Schema/NamedSchema.cs (original)
+++ avro/trunk/lang/csharp/src/apache/main/Schema/NamedSchema.cs Wed Dec 7 22:36:53 2011
@@ -101,8 +101,9 @@ namespace Avro
{
this.SchemaName = name;
this.aliases = aliases;
- if (!names.Add(name, this))
- throw new AvroException("Duplicate schema name " + name.Fullname);
+ if (null != name.Name) // Added this check for anonymous records inside Message
+ if (!names.Add(name, this))
+ throw new AvroException("Duplicate schema name " + name.Fullname);
}
/// <summary>
Modified: avro/trunk/lang/csharp/src/apache/main/Schema/RecordSchema.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/main/Schema/RecordSchema.cs?rev=1211683&r1=1211682&r2=1211683&view=diff
==============================================================================
--- avro/trunk/lang/csharp/src/apache/main/Schema/RecordSchema.cs (original)
+++ avro/trunk/lang/csharp/src/apache/main/Schema/RecordSchema.cs Wed Dec 7 22:36:53 2011
@@ -108,6 +108,7 @@ namespace Avro
IDictionary<string, Field> fieldAliasMap, SchemaNames
names)
: base(type, name, aliases, props, names)
{
+ if (!request && null == name.Name) throw new SchemaParseException("name
cannot be null for record schema.");
this.Fields = fields;
this.request = request;
this.fieldLookup = fieldMap;
Modified: avro/trunk/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs
URL: http://svn.apache.org/viewvc/avro/trunk/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs?rev=1211683&r1=1211682&r2=1211683&view=diff
==============================================================================
--- avro/trunk/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs (original)
+++ avro/trunk/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs Wed Dec 7 22:36:53 2011
@@ -17,14 +17,12 @@
*/
using System;
using System.Collections.Generic;
-using System.Text;
-using System.CodeDom;
+using System.IO;
+using System.Linq;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using NUnit.Framework;
-using Avro;
using Avro.Specific;
-using System.Reflection;
namespace Avro.Test
{
@@ -74,26 +72,7 @@ namespace Avro.Test
{
Schema schema = Schema.Parse(str);
- var codegen = new CodeGen();
- codegen.AddSchema(schema);
- var compileUnit = codegen.GenerateCode();
-
- var comparam = new CompilerParameters(new string[] {"mscorlib.dll"});
- comparam.ReferencedAssemblies.Add("System.dll");
- comparam.ReferencedAssemblies.Add("System.Core.dll");
- comparam.ReferencedAssemblies.Add(Type.GetType("Mono.Runtime") != null ? "Mono.CSharp.dll"
: "Microsoft.CSharp.dll");
- comparam.ReferencedAssemblies.Add("Avro.dll");
- comparam.GenerateInMemory = true;
- var ccp = new Microsoft.CSharp.CSharpCodeProvider();
- var units = new CodeCompileUnit[] { compileUnit };
- var compres = ccp.CompileAssemblyFromDom(comparam, units);
- if (compres == null || compres.Errors.Count>0)
- {
- for (int i=0; i<compres.Errors.Count;i++)
- Console.WriteLine(compres.Errors[i]);
- }
- if (null != compres)
- Assert.AreEqual(0, compres.Errors.Count);
+ CompilerResults compres = GenerateSchema(schema);
// instantiate object
ISpecificRecord rec = compres.CompiledAssembly.CreateInstance((string)result[0])
as ISpecificRecord;
@@ -118,5 +97,57 @@ namespace Avro.Test
Assert.AreEqual(stype, field.GetType());
}
}
+
+ [Test]
+ public void CanCodeGenTraceProtocol()
+ {
+ var traceProtocol = File.ReadAllText("../../../../../share/schemas/org/apache/avro/ipc/trace/avroTrace.avpr");
+ Protocol protocol = Protocol.Parse(traceProtocol);
+ var compilerResults = GenerateProtocol(protocol);
+
+ // instantiate object
+ var types = compilerResults.CompiledAssembly.GetTypes().Select(t => t.FullName);
+ Assert.That(4, Is.EqualTo(types.Count()));
+ Assert.That(types.Contains("org.apache.avro.ipc.trace.ID"), "Should have contained
ID type");
+ Assert.That(types.Contains("org.apache.avro.ipc.trace.Span"), "Should have contained
Span type");
+ Assert.That(types.Contains("org.apache.avro.ipc.trace.SpanEvent"), "Should have
contained SpanEvent type");
+ Assert.That(types.Contains("org.apache.avro.ipc.trace.TimestampedEvent"), "Should
have contained TimestampedEvent type");
+ }
+
+ private static CompilerResults GenerateSchema(Schema schema)
+ {
+ var codegen = new CodeGen();
+ codegen.AddSchema(schema);
+ return GenerateAssembly(codegen);
+ }
+
+ private static CompilerResults GenerateProtocol(Protocol protocol)
+ {
+ var codegen = new CodeGen();
+ codegen.AddProtocol(protocol);
+ return GenerateAssembly(codegen);
+ }
+
+ private static CompilerResults GenerateAssembly(CodeGen schema)
+ {
+ var compileUnit = schema.GenerateCode();
+
+ var comparam = new CompilerParameters(new string[] { "mscorlib.dll" });
+ comparam.ReferencedAssemblies.Add("System.dll");
+ comparam.ReferencedAssemblies.Add("System.Core.dll");
+ comparam.ReferencedAssemblies.Add(Type.GetType("Mono.Runtime") != null ? "Mono.CSharp.dll"
: "Microsoft.CSharp.dll");
+ comparam.ReferencedAssemblies.Add("Avro.dll");
+ comparam.GenerateInMemory = true;
+ var ccp = new CSharpCodeProvider();
+ var units = new[] { compileUnit };
+ var compres = ccp.CompileAssemblyFromDom(comparam, units);
+ if (compres.Errors.Count > 0)
+ {
+ for (int i = 0; i < compres.Errors.Count; i++)
+ Console.WriteLine(compres.Errors[i]);
+ }
+ Assert.AreEqual(0, compres.Errors.Count);
+ return compres;
+ }
}
}
|