Exemplo n.º 1
0
        private void AssertReceivedEvent(TxnEventA expectedA, TxnEventB expectedB)
        {
            Assert.AreEqual(1, listener.OldDataList.Count);
            Assert.AreEqual(1, listener.LastOldData.Length);
            EventBean combinedEvent = listener.LastOldData[0];

            Compare(combinedEvent, expectedA, expectedB);
            listener.Reset();
        }
Exemplo n.º 2
0
        public void TestFlow()
        {
            var a = new TxnEventA[20];
            var b = new TxnEventB[20];
            var c = new TxnEventC[20];

            int seconds = 1 * 60; // after 1 minutes

            SendEvent(new CurrentTimeEvent(seconds * 1000));
            SendEvent(a[0] = new TxnEventA("id0", seconds * 1000, "c1"));
            SendEvent(b[0] = new TxnEventB("id0", seconds * 1000));
            SendEvent(c[0] = new TxnEventC("id0", seconds * 1000, "s1"));

            seconds = 2 * 60;
            SendEvent(new CurrentTimeEvent(seconds * 1000));
            SendEvent(a[1] = new TxnEventA("id1", seconds * 1000, "c1"));

            seconds = 3 * 60;
            SendEvent(new CurrentTimeEvent(seconds * 1000));
            SendEvent(b[2] = new TxnEventB("id2", seconds * 1000));

            seconds = 4 * 60;
            SendEvent(new CurrentTimeEvent(seconds * 1000));
            SendEvent(b[3] = new TxnEventB("id3", seconds * 1000));
            SendEvent(c[3] = new TxnEventC("id3", seconds * 1000, "s1"));

            seconds = 5 * 60;
            SendEvent(new CurrentTimeEvent(seconds * 1000));
            SendEvent(a[4] = new TxnEventA("id4", seconds * 1000, "c1"));
            SendEvent(c[4] = new TxnEventC("id4", seconds * 1000, "s1"));

            seconds = 6 * 60;
            SendEvent(new CurrentTimeEvent(seconds * 1000));
            SendEvent(a[5] = new TxnEventA("id5", seconds * 1000, "c1"));
            SendEvent(b[5] = new TxnEventB("id5", seconds * 1000));

            listener.Reset();

            SendEvent(new CurrentTimeEvent(TIME_WINDOW_SIZE_MSEC + 1 * 60 * 1000)); // Expire "id0" from window
            Assert.IsFalse(listener.IsInvoked);

            SendEvent(new CurrentTimeEvent(TIME_WINDOW_SIZE_MSEC + 2 * 60 * 1000)); // Expire "id1" from window
            AssertReceivedEvent(a[1], null);

            SendEvent(new CurrentTimeEvent(TIME_WINDOW_SIZE_MSEC + 3 * 60 * 1000));
            AssertReceivedEvent(null, b[2]);

            SendEvent(new CurrentTimeEvent(TIME_WINDOW_SIZE_MSEC + 4 * 60 * 1000));
            Assert.IsFalse(listener.IsInvoked);

            SendEvent(new CurrentTimeEvent(TIME_WINDOW_SIZE_MSEC + 5 * 60 * 1000));
            Assert.IsFalse(listener.IsInvoked);

            SendEvent(new CurrentTimeEvent(TIME_WINDOW_SIZE_MSEC + 6 * 60 * 1000));
            AssertReceivedTwoEvents(a[5], b[5]);
        }
Exemplo n.º 3
0
        private void AssertCombinedEvent(TxnEventA expectedA, TxnEventB expectedB, TxnEventC expectedC)
        {
            Assert.AreEqual(1, listener.NewDataList.Count);
            Assert.AreEqual(1, listener.LastNewData.Length);
            EventBean combinedEvent = listener.LastNewData[0];

            Assert.AreSame(expectedC.TransactionId, combinedEvent.Get("transactionId"));
            Assert.AreSame(expectedB.TransactionId, combinedEvent.Get("transactionId"));
            Assert.AreSame(expectedA.TransactionId, combinedEvent.Get("transactionId"));
            Assert.AreSame(expectedA.CustomerId, combinedEvent.Get("customerId"));
            Assert.AreSame(expectedC.SupplierId, combinedEvent.Get("supplierId"));
            Assert.AreEqual(expectedC.Timestamp - expectedA.Timestamp, combinedEvent.Get("latencyAC"));
            Assert.AreEqual(expectedB.Timestamp - expectedA.Timestamp, combinedEvent.Get("latencyAB"));
            Assert.AreEqual(expectedC.Timestamp - expectedB.Timestamp, combinedEvent.Get("latencyBC"));
            listener.Reset();
        }
Exemplo n.º 4
0
        private void AssertReceivedTwoEvents(TxnEventA expectedA, TxnEventB expectedB)
        {
            Assert.AreEqual(1, listener.OldDataList.Count);
            Assert.AreEqual(2, listener.LastOldData.Length);

            // The order is not guaranteed
            if (listener.LastOldData[0].Get("A") == expectedA)
            {
                Compare(listener.LastOldData[0], expectedA, null);
                Compare(listener.LastOldData[1], null, expectedB);
            }
            else
            {
                Compare(listener.LastOldData[1], expectedA, null);
                Compare(listener.LastOldData[0], null, expectedB);
            }

            listener.Reset();
        }
Exemplo n.º 5
0
        public void TestFlow()
        {
            TxnEventA a = new TxnEventA("id1", 1, "c1");
            TxnEventB b = new TxnEventB("id1", 2);
            TxnEventC c = new TxnEventC("id1", 3, "s1");

            // send 3 events with C last
            SendEvent(a);
            SendEvent(b);
            Assert.IsFalse(listener.IsInvoked);
            SendEvent(c);
            AssertCombinedEvent(a, b, c);

            // send events not matching id
            a = new TxnEventA("id4", 4, "c2");
            b = new TxnEventB("id2", 5);
            c = new TxnEventC("id3", 6, "s2");
            SendEvent(a);
            SendEvent(b);
            Assert.IsFalse(listener.IsInvoked);
            SendEvent(c);

            // send events with B last
            a = new TxnEventA("id3", 7, "c2");
            b = new TxnEventB("id3", 8);
            SendEvent(a);
            Assert.IsFalse(listener.IsInvoked);
            SendEvent(b);
            AssertCombinedEvent(a, b, c);

            // send events with A last
            a = new TxnEventA("id6", 9, "c2");
            b = new TxnEventB("id6", 10);
            c = new TxnEventC("id6", 11, "s2");
            SendEvent(b);
            SendEvent(c);
            Assert.IsFalse(listener.IsInvoked);
            SendEvent(a);
            AssertCombinedEvent(a, b, c);
        }
Exemplo n.º 6
0
 private static void Compare(EventBean combinedEvent, TxnEventA expectedA, TxnEventB expectedB)
 {
     Assert.AreSame(expectedA, combinedEvent.Get("A"));
     Assert.AreSame(expectedB, combinedEvent.Get("B"));
     Assert.IsNull(combinedEvent.Get("C"));
 }