Exemplo n.º 1
0
        public void TestEnumDefault()
        {
            //writerSchema has "SECOND"
            Schema writerSchema = Schema.Parse("{ \"type\": \"record\", \"name\": \"EnumRecord\", \"fields\": [ { \"name\": \"enumType\", \"type\": { \"type\": \"enum\", \"name\": \"EnumType\", \"symbols\": [ \"DEFAULT\", \"FIRST\", \"SECOND\", \"THIRD\" ], \"default\": \"DEFAULT\" } } ] }");
            Schema readerSchema = Schema.Parse("{ \"type\": \"record\", \"name\": \"EnumRecord\", \"fields\": [ { \"name\": \"enumType\", \"type\": { \"type\": \"enum\", \"name\": \"EnumType\", \"symbols\": [ \"DEFAULT\", \"FIRST\", \"THIRD\" ], \"default\": \"DEFAULT\" } } ] }");

            //readerSchema is missing "SECOND" so should therefore be "DEFAULT"
            var testRecord = new EnumRecord {
                enumType = EnumType.SECOND
            };

            // serialize
            var stream = serialize(writerSchema, testRecord);

            // deserialize
            var rec2 = deserialize <EnumRecord>(stream, writerSchema, readerSchema);

            Assert.AreEqual(EnumType.DEFAULT, rec2.enumType);
        }
Exemplo n.º 2
0
        public void TestEnumResolution()
        {
            Schema writerSchema = Schema.Parse("{\"type\":\"record\",\"name\":\"EnumRecord\",\"namespace\":\"Avro.Test\"," +
                                               "\"fields\":[{\"name\":\"enumType\",\"type\": { \"type\": \"enum\", \"name\": \"EnumType\", \"symbols\": [\"FIRST\", \"SECOND\"]} }]}");

            var testRecord = new EnumRecord();

            Schema readerSchema = testRecord.Schema;

            testRecord.enumType = EnumType.SECOND;

            // serialize
            var stream = serialize(writerSchema, testRecord);

            // deserialize
            var rec2 = deserialize <EnumRecord>(stream, writerSchema, readerSchema);

            Assert.AreEqual(EnumType.SECOND, rec2.enumType);
        }
Exemplo n.º 3
0
        public void TestEnumResolution()
        {
            Schema writerSchema = Schema.Parse("{\"type\":\"record\",\"name\":\"EnumRecord\",\"namespace\":\"Avro.Test\"," +
                                        "\"fields\":[{\"name\":\"enumType\",\"type\": { \"type\": \"enum\", \"name\": \"EnumType\", \"symbols\": [\"FIRST\", \"SECOND\"]} }]}");

            Schema readerSchema = Schema.Parse("{\"type\":\"record\",\"name\":\"EnumRecord\",\"namespace\":\"Avro.Test\"," +
                                        "\"fields\":[{\"name\":\"enumType\",\"type\": { \"type\": \"enum\", \"name\": \"EnumType\", \"symbols\": [\"THIRD\", \"FIRST\", \"SECOND\"]} }]}");

            EnumRecord testRecord = new EnumRecord();
            testRecord.enumType = EnumType.SECOND;

            // serialize
            var stream = new MemoryStream();
            var binEncoder = new BinaryEncoder(stream);
            var writer = new SpecificWriter<EnumRecord>(writerSchema);
            writer.Write(testRecord, binEncoder);

            // deserialize
            stream.Position = 0;
            var decoder = new BinaryDecoder(stream);
            var reader = new SpecificReader<EnumRecord>(writerSchema, readerSchema);
            var rec2 = reader.Read(null, decoder);
            Assert.AreEqual( EnumType.SECOND, rec2.enumType );
        }