Exemplo n.º 1
0
        public static GenericRecord CreateMessage()
        {
            // The first and only type in the list is the Message type.
            var recordSchema = (RecordSchema) MailResponder.Protocol.Types[0];
            var record = new GenericRecord(recordSchema);

            record.Add("to", "wife");
            record.Add("from", "husband");
            record.Add("body", "I love you!");

            return record;
        }
Exemplo n.º 2
0
        public void TestSingleRpc()
        {
            Transceiver t = new LocalTransceiver(new TestResponder(protocol));
            var p = new GenericRecord(protocol.Messages["m"].Request);
            p.Add("x", "hello");
            var r = new GenericRequestor(t, protocol);

            for (int x = 0; x < 5; x++)
            {
                object request = r.Request("m", p);
                Assert.AreEqual("there", request);
            }
        }
        // AVRO-625 [Test] 
        // Currently, SocketTransceiver does not permit out-of-order requests on a stateful connection.
        public void Test()
        {
            var waitLatch = new CountdownLatch(1);
            var simpleResponder = new SimpleResponder(waitLatch);
            server = new SocketServer("localhost", 0, simpleResponder);

            server.Start();

            int port = server.Port;

            transceiver = new SocketTransceiver("localhost", port);
            proxy = new GenericRequestor(transceiver, SimpleResponder.Protocol);

            // Step 1:
            proxy.GetRemote(); // force handshake

            new Thread(x =>
                           {
                               // Step 2a:
                               waitLatch.Wait();

                               var ack = new GenericRecord(SimpleResponder.Protocol.Messages["ack"].Request);
                               // Step 2b:
                               proxy.Request("ack", ack);

                           }).Start();


            /*
             * 3. Execute the Client.hello("wait") RPC, which will block until the
             *    Client.ack() call has completed in the background thread.
             */

            var request = new GenericRecord(SimpleResponder.Protocol.Messages["hello"].Request);
            request.Add("greeting", "wait");

            var response = (string)proxy.Request("hello", request);

            // 4. If control reaches here, both RPCs have executed concurrently
            Assert.AreEqual("wait", response); 
        }
Exemplo n.º 4
0
        private string Send(GenericRecord message)
        {
            var request = new GenericRecord(MailResponder.Protocol.Messages["send"].Request);
            request.Add("message", message);

            var result = (string) proxy.Request("send", request);
            return result;
        }
Exemplo n.º 5
0
 private void FireAndForget(GenericRecord genericRecord)
 {
     FireAndForget(proxy, genericRecord);
 }
Exemplo n.º 6
0
        private static void FireAndForget(GenericRequestor proxy, GenericRecord genericRecord)
        {
            var request = new GenericRecord(MailResponder.Protocol.Messages["fireandforget"].Request);
            request.Add("message", genericRecord);

            proxy.Request("fireandforget", request);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Extracts the field value from the given object. In this default implementation,
        /// value should be of type GenericRecord.
        /// </summary>
        /// <param name="value">The record value from which the field needs to be extracted</param>
        /// <param name="fieldName">The name of the field in the record</param>
        /// <param name="fieldPos">The position of field in the record</param>
        /// <returns></returns>
        protected virtual object GetField(object value, string fieldName, int fieldPos)
        {
            GenericRecord d = value as GenericRecord;

            return(d[fieldName]);
        }