Esempio n. 1
0
        public void CustomEventsTest()
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();
            IRemoteCache <string, string> cache    = remoteManager.GetCache <string, string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Clear();
                cl.filterFactoryName    = "";
                cl.converterFactoryName = "";
                cl.converterFactoryName = "to-string-converter-factory";
                cl.AddListener(listener.CreatedEventAction);
                cl.AddListener(listener.ModifiedEventAction);
                cl.AddListener(listener.RemovedEventAction);
                cl.AddListener(listener.ExpiredEventAction);
                cl.AddListener(listener.CustomEventAction);
                cache.AddClientListener(cl, new string[] { }, new string[] { }, null);
                cache.Put("key1", "value1");
                AssertOnlyCustom("custom event: key1 value1", listener);
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
Esempio n. 2
0
        public void IncludeCurrentStateEventTest()
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();
            IRemoteCache <string, string> cache    = remoteManager.GetCache <string, string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Clear();
                cache.Put("key1", "value1");
                cl.filterFactoryName    = "";
                cl.converterFactoryName = "";
                cl.includeCurrentState  = true;
                cl.AddListener(listener.CreatedEventAction);
                AssertNoEvents(listener);
                cache.AddClientListener(cl, new string[] { }, new string[] { }, null);
                AssertOnlyCreated("key1", listener);
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
    public StreamSubscriptionTests(ITestOutputHelper output)
    {
        _loggerFactory = LoggerFactory.Create(
            cfg => cfg.AddXunit(output, LogLevel.Debug).SetMinimumLevel(LogLevel.Debug)
            );

        _listener = new LoggingEventListener(_loggerFactory);
    }
Esempio n. 4
0
 private void AssertNoEvents(LoggingEventListener <string> listener)
 {
     Assert.AreEqual(0, listener.createdEvents.Count);
     Assert.AreEqual(0, listener.removedEvents.Count);
     Assert.AreEqual(0, listener.modifiedEvents.Count);
     Assert.AreEqual(0, listener.expiredEvents.Count);
     Assert.AreEqual(0, listener.customEvents.Count);
 }
Esempio n. 5
0
        private void AssertOnlyCustom(string key, LoggingEventListener <string> listener)
        {
            var remoteEvent = listener.PollCustomEvent();

            Assert.AreEqual(key, marshaller.ObjectFromByteBuffer(remoteEvent.GetEventData()));
            Assert.AreEqual(0, listener.modifiedEvents.Count);
            Assert.AreEqual(0, listener.createdEvents.Count);
            Assert.AreEqual(0, listener.removedEvents.Count);
            Assert.AreEqual(0, listener.expiredEvents.Count);
        }
Esempio n. 6
0
        private void AssertOnlyExpired(string key, LoggingEventListener <string> listener)
        {
            var remoteEvent = listener.PollExpiredEvent();

            Assert.AreEqual(key, remoteEvent.GetKey());
            Assert.AreEqual(0, listener.modifiedEvents.Count);
            Assert.AreEqual(0, listener.createdEvents.Count);
            Assert.AreEqual(0, listener.removedEvents.Count);
            Assert.AreEqual(0, listener.customEvents.Count);
        }
Esempio n. 7
0
        public void ConditionalEventsTest()
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();
            IRemoteCache <string, string> cache    = remoteManager.GetCache <string, string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Clear();
                cl.filterFactoryName    = "";
                cl.converterFactoryName = "";
                cl.AddListener(listener.CreatedEventAction);
                cl.AddListener(listener.ModifiedEventAction);
                cl.AddListener(listener.RemovedEventAction);
                cl.AddListener(listener.ExpiredEventAction);
                cl.AddListener(listener.CustomEventAction);
                cache.AddClientListener(cl, new string[] { }, new string[] { }, null);
                AssertNoEvents(listener);
                cache.PutIfAbsent("key1", "value1");
                AssertOnlyCreated("key1", listener);
                cache.PutIfAbsent("key1", "value1again");
                AssertNoEvents(listener);
                cache.Replace("key1", "modified");
                AssertOnlyModified("key1", listener);
                cache.ReplaceWithVersion("key1", "modified", 0);
                AssertNoEvents(listener);
                IVersionedValue <string> versioned = cache.GetVersioned("key1");
                //TODO: this needs conversion from long to ulong (is it a bug?)
                cache.ReplaceWithVersion("key1", "modified", versioned.GetVersion());
                AssertOnlyModified("key1", listener);
                cache.RemoveWithVersion("key1", 0);
                AssertNoEvents(listener);
                versioned = cache.GetVersioned("key1");
                cache.RemoveWithVersion("key1", versioned.GetVersion());
                AssertOnlyRemoved("key1", listener);
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
        public static void RecordsNestedSerializationCalls()
        {
            // First, serialization

            using LoggingEventListener listener = new LoggingEventListener();

            MemoryStream    ms        = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Serialize(ms, new ClassWithNestedDeserialization());
            string[] capturedLog = listener.CaptureLog();
            ms.Position = 0;

            string[] expected = new string[]
            {
                "SerializationStart [Start, 00000001]: <no payload>",
                "SerializingObject [Info, 00000001]: " + typeof(ClassWithNestedDeserialization).AssemblyQualifiedName,
                "SerializationStart [Start, 00000001]: <no payload>",
                "SerializingObject [Info, 00000001]: " + typeof(Address).AssemblyQualifiedName,
                "SerializationStop [Stop, 00000001]: <no payload>",
                "SerializationStop [Stop, 00000001]: <no payload>",
            };

            Assert.Equal(expected, capturedLog);
            listener.ClearLog();

            // Then, deserialization

            ms.Position = 0;
            formatter.Deserialize(ms);
            capturedLog = listener.CaptureLog();

            expected = new string[]
            {
                "DeserializationStart [Start, 00000002]: <no payload>",
                "DeserializingObject [Info, 00000002]: " + typeof(ClassWithNestedDeserialization).AssemblyQualifiedName,
                "DeserializationStart [Start, 00000002]: <no payload>",
                "DeserializingObject [Info, 00000002]: " + typeof(Address).AssemblyQualifiedName,
                "DeserializationStop [Stop, 00000002]: <no payload>",
                "DeserializationStop [Stop, 00000002]: <no payload>",
            };

            Assert.Equal(expected, capturedLog);
        }
        public static void RecordsSerialization()
        {
            using LoggingEventListener listener = new LoggingEventListener();

            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Serialize(Stream.Null, CreatePerson());
            string[] capturedLog = listener.CaptureLog();

            string[] expected = new string[]
            {
                "SerializationStart [Start, 00000001]: <no payload>",
                "SerializingObject [Info, 00000001]: " + typeof(Person).AssemblyQualifiedName,
                "SerializingObject [Info, 00000001]: " + typeof(Address).AssemblyQualifiedName,
                "SerializationStop [Stop, 00000001]: <no payload>",
            };

            Assert.Equal(expected, capturedLog);
        }
Esempio n. 10
0
        public void FilterEventsTest()
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();
            IRemoteCache <string, string> cache    = remoteManager.GetCache <string, string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Clear();
                cl.filterFactoryName    = "string-is-equal-filter-factory";
                cl.converterFactoryName = "";
                cl.AddListener(listener.CreatedEventAction);
                cl.AddListener(listener.ModifiedEventAction);
                cl.AddListener(listener.RemovedEventAction);
                cl.AddListener(listener.ExpiredEventAction);
                cl.AddListener(listener.CustomEventAction);
                cache.AddClientListener(cl, new string[] { "wantedkeyprefix" }, new string[] { }, null);
                AssertNoEvents(listener);
                cache.Put("key1", "value1");
                cache.Put("wantedkeyprefix_key1", "value2");
                //only one received; one is ignored
                AssertOnlyCreated("wantedkeyprefix_key1", listener);
                AssertNoEvents(listener);
                cache.Replace("key1", "modified");
                cache.Replace("wantedkeyprefix_key1", "modified");
                AssertOnlyModified("wantedkeyprefix_key1", listener);
                AssertNoEvents(listener);
                cache.Remove("key1");
                cache.Remove("wantedkeyprefix_key1");
                AssertOnlyRemoved("wantedkeyprefix_key1", listener);
                AssertNoEvents(listener);
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
        public static void RecordsDeserialization()
        {
            MemoryStream    ms        = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Serialize(ms, CreatePerson());
            ms.Position = 0;

            using LoggingEventListener listener = new LoggingEventListener();
            formatter.Deserialize(ms);
            string[] capturedLog = listener.CaptureLog();

            string[] expected = new string[]
            {
                "DeserializationStart [Start, 00000002]: <no payload>",
                "DeserializingObject [Info, 00000002]: " + typeof(Person).AssemblyQualifiedName,
                "DeserializingObject [Info, 00000002]: " + typeof(Address).AssemblyQualifiedName,
                "DeserializationStop [Stop, 00000002]: <no payload>",
            };

            Assert.Equal(expected, capturedLog);
        }
Esempio n. 12
0
        public void BasicEventsTest()
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();
            IRemoteCache <string, string> cache    = remoteManager.GetCache <string, string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Clear();
                cl.filterFactoryName    = "";
                cl.converterFactoryName = "";
                cl.AddListener(listener.CreatedEventAction);
                cl.AddListener(listener.ModifiedEventAction);
                cl.AddListener(listener.RemovedEventAction);
                cl.AddListener(listener.ExpiredEventAction);
                cl.AddListener(listener.CustomEventAction);
                cache.AddClientListener(cl, new string[] { }, new string[] { }, null);
                AssertNoEvents(listener);
                cache.Put("key1", "value1");
                AssertOnlyCreated("key1", listener);
                cache.Put("key1", "value1bis");
                AssertOnlyModified("key1", listener);
                cache.Remove("key1");
                AssertOnlyRemoved("key1", listener);
                cache.Put("key1", "value1", 100, TimeUnit.MILLISECONDS);
                AssertOnlyCreated("key1", listener);
                TimeUtils.WaitFor(() => { return(cache.Get("key1") == null); });
                AssertOnlyExpired("key1", listener);
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
Esempio n. 13
0
        public void RemoteTaskWithIntArgs()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.AddServer().Host("127.0.0.1").Port(11222);
            conf.ConnectionTimeout(90000).SocketTimeout(6000);
            remoteManager = new RemoteCacheManager(conf.Build(), true);
            string script = "// mode=local,language=javascript \n"
                            + "var x = k+v; \n"
                            + "x; \n";
            LoggingEventListener <string> listener    = new LoggingEventListener <string>();
            IRemoteCache <string, string> testCache   = remoteManager.GetCache <string, string>();
            IRemoteCache <string, string> scriptCache = remoteManager.GetCache <string, string>(PROTOBUF_SCRIPT_CACHE_NAME, new JBasicMarshaller());
            const string scriptName = "putit-get.js";

            scriptCache.Put(scriptName, script);
            Dictionary <string, object> scriptArgs = new Dictionary <string, object>();

            scriptArgs.Add("k", (int)1);
            scriptArgs.Add("v", (int)2);
            object v = testCache.Execute(scriptName, scriptArgs);

            Assert.AreEqual(3, v);
        }