public void TestChangeDefaultSerialization() { var config = new SerializationConfig(); ISerializer ser = new StringSerializer(); IDeserializer deser = new StringDeserializer(); var s = config.GetSerializersForTopic("topicnotfound"); Assert.That(s, Is.EqualTo(Tuple.Create(ByteArraySerialization.DefaultSerializer, ByteArraySerialization.DefaultSerializer))); var d = config.GetDeserializersForTopic("topicnotfound"); Assert.That(d, Is.EqualTo(Tuple.Create(ByteArraySerialization.DefaultDeserializer, ByteArraySerialization.DefaultDeserializer))); config.SetDefaultSerializers(ser, ser); config.SetDefaultDeserializers(deser, deser); s = config.GetSerializersForTopic("topicnotfound"); Assert.That(s, Is.EqualTo(Tuple.Create(ser, ser))); d = config.GetDeserializersForTopic("topicnotfound"); Assert.That(d, Is.EqualTo(Tuple.Create(deser, deser))); }
public void TestSerializationConfig() { var config = new SerializationConfig(); ISerializer ser = new StringSerializer(); IDeserializer deser = new StringDeserializer(); var t1 = Tuple.Create(ser, ser); var t2 = Tuple.Create(ser, ser); Assert.That(t1, Is.EqualTo(t2)); var s = config.GetSerializersForTopic("topicnotfound"); Assert.That(s, Is.EqualTo(Tuple.Create(ByteArraySerialization.DefaultSerializer, ByteArraySerialization.DefaultSerializer))); var d = config.GetDeserializersForTopic("topicnotfound"); Assert.That(d, Is.EqualTo(Tuple.Create(ByteArraySerialization.DefaultDeserializer, ByteArraySerialization.DefaultDeserializer))); config.SetSerializersForTopic("topicnotfound", ser, ser); config.SetDeserializersForTopic("topicnotfound", deser, deser); s = config.GetSerializersForTopic("topicnotfound"); Assert.That(s, Is.EqualTo(Tuple.Create(ser, ser))); d = config.GetDeserializersForTopic("topicnotfound"); Assert.That(d, Is.EqualTo(Tuple.Create(deser, deser))); var config2 = new SerializationConfig(config); s = config2.GetSerializersForTopic("topicnotfound"); Assert.That(s, Is.EqualTo(Tuple.Create(ser, ser))); d = config2.GetDeserializersForTopic("topicnotfound"); Assert.That(d, Is.EqualTo(Tuple.Create(deser, deser))); config2.SetSerializersForTopic("topicnotfound", null, ser); config2.SetDeserializersForTopic("topicnotfound", null, deser); s = config2.GetSerializersForTopic("topicnotfound"); Assert.That(s, Is.EqualTo(Tuple.Create(ByteArraySerialization.DefaultSerializer, ser))); d = config2.GetDeserializersForTopic("topicnotfound"); Assert.That(d, Is.EqualTo(Tuple.Create(ByteArraySerialization.DefaultDeserializer, deser))); config2.SetSerializersForTopic("topicnotfound", ser, null); config2.SetDeserializersForTopic("topicnotfound", deser, null); s = config2.GetSerializersForTopic("topicnotfound"); Assert.That(s, Is.EqualTo(Tuple.Create(ser, ByteArraySerialization.DefaultSerializer))); d = config2.GetDeserializersForTopic("topicnotfound"); Assert.That(d, Is.EqualTo(Tuple.Create(deser, ByteArraySerialization.DefaultDeserializer))); }
public void TestSerializeProduceRequest() { var produce = new ProduceRequest { Timeout = 1223, RequiredAcks = 1, TopicsData = new[] { new TopicData <PartitionData> { TopicName = "barbu", PartitionsData = new[] { new PartitionData { Partition = 22, CompressionCodec = CompressionCodec.None, Messages = new[] { new Message { Value = TheValue } }, } } }, } }; var config = new SerializationConfig(); config.SetSerializersForTopic("barbu", new StringSerializer(), new StringSerializer()); config.SetDeserializersForTopic("barbu", new StringDeserializer(), new StringDeserializer()); using (var serialized = produce.Serialize(new ReusableMemoryStream(null), 321, ClientId, config)) { CheckHeader(Basics.ApiKey.ProduceRequest, 0, 321, TheClientId, serialized); Assert.AreEqual(produce.RequiredAcks, BigEndianConverter.ReadInt16(serialized)); Assert.AreEqual(produce.Timeout, BigEndianConverter.ReadInt32(serialized)); Assert.AreEqual(1, BigEndianConverter.ReadInt32(serialized)); // 1 topic data Assert.AreEqual("barbu", Basics.DeserializeString(serialized)); Assert.AreEqual(1, BigEndianConverter.ReadInt32(serialized)); // 1 partition data Assert.AreEqual(22, BigEndianConverter.ReadInt32(serialized)); var msgs = FetchPartitionResponse.DeserializeMessageSet(serialized, config.GetDeserializersForTopic("barbu")); Assert.AreEqual(1, msgs.Count); //Assert.AreEqual(TheValue, Encoding.UTF8.GetString(msgs[0].Message.Value)); Assert.AreEqual(TheValue, msgs[0].Message.Value as string); } }