Exemplo n.º 1
0
 public MillipedeConfiguration(MillipedeRecorder recorder)
 {
     InitializeComponent();
     this.recorder = recorder;
     rbPlayback.Checked = true;
     UpdateUI();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Check and configure the provided recorder, if not yet configured.
 /// </summary>
 /// <param name="recorder">the recorder to possibly configure</param>
 /// <returns>the recorder instance</returns>
 public static MillipedeRecorder Configure(MillipedeRecorder recorder)
 {
     if (recorder.Mode == MillipedeMode.Unconfigured)
     {
         MillipedeConfiguration dialog = new MillipedeConfiguration(recorder);
         dialog.ShowDialog();
     }
     return recorder;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Instanciates a millipede acceptor and wraps it around an existing underlying
        /// IAcceptor.
        /// </summary>
        /// <param name="underlyingAcceptor">The existing underlying IAcceptor</param>
        /// <param name="recorder">The Millipede Replayer/Recorder</param>
        protected MillipedeAcceptor(IAcceptor underlyingAcceptor, MillipedeRecorder recorder)
        {
            this.underlyingAcceptor = underlyingAcceptor;
            this.underlyingAcceptor.ValidateTransport += UnderlyingAcceptor_ValidateTransport;

            this.recorder = recorder;
            milliDescriptor = recorder.GenerateDescriptor(underlyingAcceptor);
            if (recorder.Mode != MillipedeMode.Playback)
            {
                // we only pass-through recorded connections in playback mode
                this.underlyingAcceptor.NewTransportAccepted += UnderlyingAcceptor_NewTransportEvent;
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Wrap the provided connector for use with Millipede.
 /// If the Millipede recorder is unconfigured, we cause
 /// a dialog to configure the recorder.
 /// If the Millipede recorder is configured to be passthrough,
 /// we return the connector unwrapped.
 /// </summary>
 /// <param name="connector">the connector to be wrapped</param>
 /// <param name="recorder">the Millipede recorder</param>
 /// <returns>an appropriately configured connector</returns>
 public static IConnector Wrap(IConnector connector, MillipedeRecorder recorder)
 {
     if (recorder.Mode == MillipedeMode.PassThrough)
     {
         return connector;
     }
     return new MillipedeConnector(connector, recorder);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Create a recording recorder that wraps around an existing underlying
 /// IConnector.
 /// </summary>
 /// <param name="underlyingConnector">The existing underlying IConnector</param>
 /// <param name="recorder">The Millipede Replayer/Recorder</param>
 protected MillipedeConnector(IConnector underlyingConnector, MillipedeRecorder recorder)
 {
     milliDescriptor = recorder.GenerateDescriptor(underlyingConnector);
     this.recorder = recorder;
     this.underlyingConnector = underlyingConnector;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Wrap the provided connectors for use with Millipede.
 /// If the Millipede recorder is unconfigured, we cause
 /// a dialog to configure the recorder.
 /// If the Millipede recorder is configured to be passthrough,
 /// we leave the connectors unwrapped.
 /// </summary>
 /// <param name="connectors">the acceptors to be wrapped</param>
 /// <param name="recorder">the Millipede recorder</param>
 /// <returns>a collection of appropriately configured acceptors</returns>
 public static ICollection<IConnector> Wrap(ICollection<IConnector> connectors,
     MillipedeRecorder recorder)
 {
     if (recorder.Mode == MillipedeMode.PassThrough)
     {
         return connectors;
     }
     List<IConnector> wrappers = new List<IConnector>();
     foreach (IConnector conn in connectors)
     {
         wrappers.Add(new MillipedeConnector(conn, recorder));
     }
     return wrappers;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Wrap the provided acceptor for use with Millipede.
 /// If the Millipede recorder is unconfigured, we cause
 /// a dialog to configure the recorder.
 /// If the Millipede recorder is configured to be passthrough,
 /// we return the acceptor unwrapped.
 /// </summary>
 /// <param name="acceptor">the acceptor to be wrapped</param>
 /// <param name="recorder">the Millipede recorder</param>
 /// <returns>an appropriately configured acceptor</returns>
 public static IAcceptor Wrap(IAcceptor acceptor, MillipedeRecorder recorder)
 {
     if (recorder.Mode == MillipedeMode.PassThrough)
     {
         return acceptor;
     }
     return new MillipedeAcceptor(acceptor, recorder);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Wrap the provided acceptors for use with Millipede.
 /// If the Millipede recorder is unconfigured, we cause
 /// a dialog to configure the recorder.
 /// If the Millipede recorder is configured to be passthrough,
 /// we leave the acceptors unwrapped.
 /// </summary>
 /// <param name="acceptors">the acceptors to be wrapped</param>
 /// <param name="recorder">the Millipede recorder</param>
 /// <returns>a collection of appropriately configured acceptors</returns>
 public static ICollection<IAcceptor> Wrap(ICollection<IAcceptor> acceptors,
     MillipedeRecorder recorder)
 {
     if (recorder.Mode == MillipedeMode.PassThrough)
     {
         return acceptors;
     }
     List<IAcceptor> wrappers = new List<IAcceptor>();
     foreach(IAcceptor acc in acceptors)
     {
         wrappers.Add(new MillipedeAcceptor(acc, recorder));
     }
     return wrappers;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Creates a recording wrapper for any given ITransport
 /// </summary>
 /// <param name="underlyingTransport">The underlying <see cref="ITransport"/></param>
 /// <param name="recorder">Millepede recorder</param>
 /// <param name="milliTransportDescriptor">the Millipede descriptor for <see cref="underlyingTransport"/></param>
 public MillipedeTransport(ITransport underlyingTransport, MillipedeRecorder recorder,
     object milliTransportDescriptor)
 {
     Debug.Assert(recorder.Mode == MillipedeMode.Record);
     this.underlyingTransport = underlyingTransport;
     this.recorder = recorder;
     milliDescriptor = milliTransportDescriptor;
     this.underlyingTransport.PacketReceived += _underlyingTransports_PacketReceivedEvent;
     this.underlyingTransport.PacketSent += _underlyingTransports_PacketSentEvent;
     this.underlyingTransport.ErrorEvent += _underlyingTransport_ErrorEvent;
     running = true;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a replaying wrapper for a former transport.
        /// </summary>
        /// <param name="recorder">Millepede recorder</param>
        /// <param name="milliTransportDescriptor">the millipede descriptor for this object</param>
        /// <param name="transportName">the <see cref="ITransport.Name"/></param>
        /// <param name="capabilities">the <see cref="ITransport.Capabilities"/></param>
        /// <param name="reliabilty">the <see cref="ITransport.Reliability"/></param>
        /// <param name="ordering">the <see cref="ITransport.Ordering"/></param>
        /// <param name="maxPacketSize">the <see cref="ITransport.MaximumPacketSize"/></param>
        public MillipedeTransport(MillipedeRecorder recorder, object milliTransportDescriptor, 
            string transportName, IDictionary<string, string> capabilities,
            Reliability reliabilty, Ordering ordering, uint maxPacketSize)
        {
            Debug.Assert(recorder.Mode == MillipedeMode.Playback);
            this.recorder = recorder;
            milliDescriptor = milliTransportDescriptor;
            replayName = transportName;
            replayCapabilities = capabilities;
            replayReliability = reliabilty;
            replayOrdering = ordering;
            replayMaximumPacketSize = maxPacketSize;

            running = true;
        }
Exemplo n.º 11
0
        public void Dispose()
        {
            lock (this)
            {
                if(this == singleton) { singleton = null; }
                if(syncingTimer != null) { syncingTimer.Dispose(); }
                syncingTimer = null;

                if(sinkFile != null)
                {
                    if(sinkFile != null && dataSink != null)
                    {
                        SyncRecording(null);
                    }
                    if(sinkFile != null) { sinkFile.Close(); }
                    if(dataSink != null) { dataSink.Dispose(); }
                    sinkFile = null;
                    dataSink = null;
                }
                assignedDescriptors = null;
            }
            mode = MillipedeMode.PassThrough;
        }
Exemplo n.º 12
0
        protected void TryMillipedeException(Exception exception)
        {
            string tempFileName = Path.GetTempFileName();
            toBeDeleted.Add(tempFileName);

            // Create the mock connector
            MockConnector mockConnector = new MockConnector();
            mockConnector.CreateTransport = delegate { throw exception; };
            mockConnector.Start();

            recorder = new MillipedeRecorder();
            recorder.StartRecording(tempFileName);
            Assert.AreEqual(MillipedeMode.Record, recorder.Mode);
            Assert.AreEqual(0, recorder.NumberEvents);
            MillipedeConnector connector =
                (MillipedeConnector)MillipedeConnector.Wrap(mockConnector, recorder);
            try
            {
                connector.Connect("localhost", "9999", new Dictionary<string, string>());
                Assert.Fail("should have thrown CannotConnectException");
            }
            catch(GTException) { /* ignored */ }
            Assert.AreEqual(1, recorder.NumberEvents);

            recorder.Dispose(); // don't want the disposes add to the list
            mockConnector.Dispose();
            recorder = new MillipedeRecorder();
            recorder.StartReplaying(tempFileName);
            Assert.AreEqual(0, recorder.NumberEvents);
            connector = (MillipedeConnector)MillipedeConnector.Wrap(mockConnector = new MockConnector(),
                recorder);
            try
            {
                connector.Connect("localhost", "9999", new Dictionary<string, string>());
                Assert.Fail("should have thrown " + exception.GetType());
            }
            catch (Exception e)
            {
                Assert.AreEqual(exception.GetType(), e.GetType());
            }
            Assert.AreEqual(1, recorder.NumberEvents);

            recorder.Dispose();
        }
Exemplo n.º 13
0
 protected void SetUp()
 {
     toBeDeleted.Clear();
     recorder = new MillipedeRecorder();
 }
Exemplo n.º 14
0
        public void TestMillipedeConnector()
        {
            string tempFileName = Path.GetTempFileName();
            toBeDeleted.Add(tempFileName);

            // Create the mock connector and transport
            MockTransport mockTransport = new MockTransport("MOCK", new Dictionary<string, string>(),
                Reliability.Reliable, Ordering.Ordered, 1024);
            uint packetsSent = 0;
            mockTransport.PacketSent += delegate { packetsSent++; };
            MockConnector mockConnector = new MockConnector();
            mockConnector.CreateTransport = delegate { return mockTransport; };
            mockConnector.Start();

            recorder.StartRecording(tempFileName);
            Assert.AreEqual(MillipedeMode.Record, recorder.Mode);
            Assert.AreEqual(0, recorder.NumberEvents);
            MillipedeConnector connector =
                (MillipedeConnector)MillipedeConnector.Wrap(mockConnector, recorder);
            ITransport transport = connector.Connect("localhost", "9999", new Dictionary<string, string>());
            Assert.IsInstanceOfType(typeof(MillipedeTransport), transport);
            Assert.AreEqual(1, recorder.NumberEvents);
            transport.SendPacket(new TransportPacket(new byte[10]));
            Assert.AreEqual(2, recorder.NumberEvents);
            Assert.AreEqual(1, packetsSent, "millipede didn't pass down packet-send in record");
            Thread.Sleep(50);  // give a good amount of time for the test below
            mockTransport.InjectReceivedPacket(new byte[5]);
            Assert.AreEqual(3, recorder.NumberEvents);

            recorder.Dispose(); // don't want the disposes add to the list
            mockConnector.Dispose();
            mockTransport.Dispose();

            recorder = new MillipedeRecorder();
            recorder.StartReplaying(tempFileName);
            Assert.AreEqual(0, recorder.NumberEvents);
            connector = (MillipedeConnector)MillipedeConnector.Wrap(mockConnector = new MockConnector(),
                recorder);
            transport = connector.Connect("localhost", "9999", new Dictionary<string, string>());
            transport.PacketReceived += (packet, t) =>
            {
                Assert.AreEqual(new byte[5], packet.ToArray());
                Assert.AreEqual(3, recorder.NumberEvents);
            };

            Assert.IsInstanceOfType(typeof(MillipedeTransport), transport);
            Assert.AreEqual(1, recorder.NumberEvents);
            transport.SendPacket(new TransportPacket(new byte[10]));
            Assert.AreEqual(2, recorder.NumberEvents);
            transport.Update();
            for (int i = 0; i < 5 && recorder.NumberEvents == 2; i++)
            {
                Thread.Sleep(100);
                transport.Update();
            }
            Assert.AreEqual(3, recorder.NumberEvents);  // should have received the packet too
        }
Exemplo n.º 15
0
        public void BaseTestUniqueStableDescriptor()
        {
            string[] values = { typeof(String).FullName, "test", "bar", "test" };
            foreach (string value in values) {
                object d1 = recorder.GenerateDescriptor(value);
                recorder.Dispose();
                recorder = new MillipedeRecorder();
                object d2 = recorder.GenerateDescriptor(value);
                recorder.Dispose();
                Assert.AreEqual(d1,d2);
                recorder = new MillipedeRecorder();
            }

            Dictionary<object, object> descriptors = new Dictionary<object, object>();
            foreach (string value in values)
            {
                object d1 = recorder.GenerateDescriptor(value);
                Assert.IsFalse(descriptors.ContainsKey(d1));
                descriptors[d1] = d1;
            }
        }