Esempio n. 1
0
        private void SetupPatterns(MobileUserBean mobileUser)
        {
            double locXLow  = mobileUser.LocationX - PROXIMITY_RANGE;
            double locXHigh = mobileUser.LocationX + PROXIMITY_RANGE;
            double locYLow  = mobileUser.LocationY - PROXIMITY_RANGE;
            double locYHigh = mobileUser.LocationY + PROXIMITY_RANGE;

            _locateOther = _epService.EPAdministrator.CreatePattern(
                "every other=" + typeof(MobileUserBean).FullName +
                "(locationX in [" + locXLow + ":" + locXHigh + "]," +
                "locationY in [" + locYLow + ":" + locYHigh + "]," +
                "myGender='" + mobileUser.PreferredGender + "'," +
                "myAgeRange='" + mobileUser.PreferredAgeRange + "'," +
                "myHairColor='" + mobileUser.PreferredHairColor + "'," +
                "preferredGender='" + mobileUser.MyGender + "'," +
                "preferredAgeRange='" + mobileUser.MyAgeRange + "'," +
                "preferredHairColor='" + mobileUser.MyHairColor + "'" +
                ")");

            _locateOther.Events +=
                delegate(Object sender, UpdateEventArgs e)
            {
                var other = (MobileUserBean)e.NewEvents[0]["other"];
                var alert = new MatchAlertBean(other.UserId, _mobileUserId);
                _matchAlertListener.Emitted(alert);
            };
        }
Esempio n. 2
0
        public void TestLocationChanges()
        {
            var sender = _runtime.EventService.GetEventSender(typeof(MobileUserBean).Name);

            var user1 = new MobileUserBean(USER_ID_1, 10, 10,
                                           Gender.MALE, HairColor.BLONDE, AgeRange.AGE_4,
                                           Gender.FEMALE, HairColor.BLACK, AgeRange.AGE_1);

            sender.SendEvent(user1);

            var user2 = new MobileUserBean(USER_ID_2, 10, 10,
                                           Gender.FEMALE, HairColor.BLACK, AgeRange.AGE_1,
                                           Gender.MALE, HairColor.BLONDE, AgeRange.AGE_4);

            sender.SendEvent(user2);

            Assert.AreEqual(1, _listener.GetAndClearEmittedCount());
            _runtime.EventService.SendEventBean(user1.Copy().WithLocation(8.99999, 10), EVENTTYPE);
            Assert.AreEqual(0, _listener.GetAndClearEmittedCount());

            _runtime.EventService.SendEventBean(user1.Copy().WithLocation(9, 10), EVENTTYPE);
            Assert.AreEqual(1, _listener.GetAndClearEmittedCount());

            _runtime.EventService.SendEventBean(user1.Copy().WithLocation(11, 10), EVENTTYPE);
            Assert.AreEqual(1, _listener.GetAndClearEmittedCount());

            _runtime.EventService.SendEventBean(user1.Copy().WithLocation(11.0000001, 10), EVENTTYPE);
            Assert.AreEqual(0, _listener.GetAndClearEmittedCount());

            _runtime.EventService.SendEventBean(user2.Copy().WithLocation(10.0000001, 9), EVENTTYPE);

            Assert.AreEqual(1, _listener.GetAndClearEmittedCount());
        }
Esempio n. 3
0
        public MatchMakingMonitor(EPServiceProvider epService, MobileUserBean mobileUser, MatchAlertListener matchAlertListener)
        {
            _epService          = epService;
            _matchAlertListener = matchAlertListener;
            _mobileUserId       = mobileUser.UserId;

            // Create patterns that listen to other users
            SetupPatterns(mobileUser);

            // Listen to my own location changes so my data is up-to-date
            EPStatement locationChange = _epService.EPAdministrator.CreatePattern(
                "every myself=" + typeof(MobileUserBean).FullName +
                "(UserId=" + mobileUser.UserId + ")");

            locationChange.Events +=
                delegate(Object sender, UpdateEventArgs e) {
                // When my location changed, re-establish pattern
                _locateOther.RemoveAllEventHandlers();
                var myself = (MobileUserBean)e.NewEvents[0]["myself"];
                SetupPatterns(myself);
            };
        }
Esempio n. 4
0
        public void TestPreferredMatchingBackwards()
        {
            var sender = _runtime.EventService.GetEventSender(typeof(MobileUserBean).Name);
            var user1  = new MobileUserBean(USER_ID_1, 10, 10,
                                            Gender.MALE, HairColor.RED, AgeRange.AGE_6,
                                            Gender.FEMALE, HairColor.BLACK, AgeRange.AGE_5);

            sender.SendEvent(user1);

            // Test all combinations
            foreach (Gender gender in Enum.GetValues(typeof(Gender)))
            {
                foreach (HairColor color in Enum.GetValues(typeof(HairColor)))
                {
                    foreach (AgeRange age in AgeRange.Values)
                    {
                        // Try user preferences backwards
                        var userB = new MobileUserBean(USER_ID_2, 10, 10,
                                                       gender, color, age,
                                                       Gender.MALE, HairColor.RED, AgeRange.AGE_6);
                        sender.SendEvent(userB);

                        if (_listener.EmittedList.Count == 1)
                        {
                            Assert.AreEqual(gender, Gender.FEMALE);
                            Assert.AreEqual(color, HairColor.BLACK);
                            Assert.AreEqual(age, AgeRange.AGE_5);
                            _listener.ClearEmitted();
                        }
                        else
                        {
                            Assert.AreEqual(0, _listener.GetAndClearEmittedCount());
                        }
                    }
                }
            }
        }
        public void TestLocationChanges()
        {
            var user1 = new MobileUserBean(USER_ID_1, 10, 10,
                                           Gender.MALE, HairColor.BLONDE, AgeRange.AGE_4,
                                           Gender.FEMALE, HairColor.BLACK, AgeRange.AGE_1);

            _epService.EPRuntime.SendEvent(user1);

            var user2 = new MobileUserBean(USER_ID_2, 10, 10,
                                           Gender.FEMALE, HairColor.BLACK, AgeRange.AGE_1,
                                           Gender.MALE, HairColor.BLONDE, AgeRange.AGE_4);

            _epService.EPRuntime.SendEvent(user2);

            Assert.AreEqual(1, _listener.GetAndClearEmittedCount());

            user1.SetLocation(8.99999, 10);
            _epService.EPRuntime.SendEvent(user1);
            Assert.AreEqual(0, _listener.GetAndClearEmittedCount());

            user1.SetLocation(9, 10);
            _epService.EPRuntime.SendEvent(user1);
            Assert.AreEqual(1, _listener.GetAndClearEmittedCount());

            user1.SetLocation(11, 10);
            _epService.EPRuntime.SendEvent(user1);
            Assert.AreEqual(1, _listener.GetAndClearEmittedCount());

            user1.SetLocation(11.0000001, 10);
            _epService.EPRuntime.SendEvent(user1);
            Assert.AreEqual(0, _listener.GetAndClearEmittedCount());

            user2.SetLocation(10.0000001, 9);
            _epService.EPRuntime.SendEvent(user2);
            Assert.AreEqual(1, _listener.GetAndClearEmittedCount());
        }
Esempio n. 6
0
        public void Run()
        {
            Log.Info("Setting up EPL");
            // This code runs as part of the automated regression test suite; Therefore disable internal timer theading to safe resources
            var config = new Configuration();

            config.EngineDefaults.Threading.IsInternalTimerEnabled = false;

            var listener  = new MatchAlertListener();
            var epService = EPServiceProviderManager.GetProvider(_engineURI, config);

            epService.Initialize();

            new MatchMakingMonitor(epService, listener);

            Log.Info("Sending user information");
            var user1 = new MobileUserBean(1, 10, 10,
                                           Gender.MALE, HairColor.BLONDE, AgeRange.AGE_4,
                                           Gender.FEMALE, HairColor.BLACK, AgeRange.AGE_1);

            epService.EPRuntime.SendEvent(user1);

            var user2 = new MobileUserBean(2, 10, 10,
                                           Gender.FEMALE, HairColor.BLACK, AgeRange.AGE_1,
                                           Gender.MALE, HairColor.BLONDE, AgeRange.AGE_4);

            epService.EPRuntime.SendEvent(user2);

            Log.Info("Sending some near locations");
            user1.SetLocation(8.99999, 10);
            epService.EPRuntime.SendEvent(user1);

            user1.SetLocation(9, 10);
            epService.EPRuntime.SendEvent(user1);

            user1.SetLocation(11, 10);
            epService.EPRuntime.SendEvent(user1);

            user1.SetLocation(11.0000001, 10);
            epService.EPRuntime.SendEvent(user1);

            user2.SetLocation(10.0000001, 9);
            epService.EPRuntime.SendEvent(user2);

            user1 = new MobileUserBean(1, 10, 10,
                                       Gender.MALE, HairColor.RED, AgeRange.AGE_6,
                                       Gender.FEMALE, HairColor.BLACK, AgeRange.AGE_5);
            epService.EPRuntime.SendEvent(user1);

            // Test all combinations
            foreach (var gender in EnumHelper.GetValues <Gender>())
            {
                foreach (var color in EnumHelper.GetValues <HairColor>())
                {
                    foreach (var age in EnumHelper.GetValues <AgeRange>())
                    {
                        // Try user preferences
                        var userA = new MobileUserBean(2, 10, 10,
                                                       Gender.FEMALE, HairColor.BLACK, AgeRange.AGE_5,
                                                       gender, color, age);
                        epService.EPRuntime.SendEvent(userA);
                    }
                }
            }

            var random = new Random();
            int maxEvents;

            if (_continuousSimulation)
            {
                maxEvents = int.MaxValue;
            }
            else
            {
                maxEvents = 100000;
                Log.Info("Sending 100k of random locations");
            }

            for (var i = 1; i < maxEvents; i++)
            {
                var x = 10 + random.Next(i) / 100000;
                var y = 10 + random.Next(i) / 100000;

                user2.SetLocation(x, y);
                epService.EPRuntime.SendEvent(user2);

                if (_continuousSimulation)
                {
                    try {
                        Thread.Sleep(200);
                    } catch (ThreadInterruptedException e) {
                        Log.Debug("Interrupted", e);
                    }
                }
            }

            Log.Info("Done.");
        }