Exemplo n.º 1
0
        public void TestWithSpecificOptions()
        {
            const int    expectedDefaultDatabase   = 5;
            const int    expectedConnectRetryCount = 5;
            const int    expectedKeepAliveSeconds  = 20;
            const int    expectedSyncTimeout       = 7500;
            const string expectedTieBreakerKey     = "breakerKey";
            const string expectedChannelPrefix     = "pfx";
            const string expectedConfigChannel     = "ch1";
            const string expectedVersion           = "3.0.4";
            const int    expectedWriteBuffer       = 100;
            const string expectedSslHost           = "localhost";

            var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 2);

            var redisConnection = objectFactory.GetObject <RedisConnection>("strongConnection");

            Assert.IsTrue(redisConnection.Config.EndPoints.Count > 0);
            Assert.IsNotEmpty(redisConnection.Config.Password);
            Assert.AreEqual(expectedDefaultDatabase, redisConnection.Config.DefaultDatabase);
            Assert.True(redisConnection.Config.AbortOnConnectFail);
            Assert.True(redisConnection.Config.AllowAdmin);
            Assert.AreEqual(expectedChannelPrefix, redisConnection.Config.ChannelPrefix.ToString());
            Assert.AreEqual(expectedConnectRetryCount, redisConnection.Config.ConnectRetry);
            Assert.AreEqual(expectedConfigChannel, redisConnection.Config.ConfigurationChannel);
            Assert.AreEqual(expectedKeepAliveSeconds, redisConnection.Config.KeepAlive);
            Assert.True(redisConnection.Config.ResolveDns);
            Assert.False(redisConnection.Config.Ssl);
            Assert.AreEqual(expectedSslHost, redisConnection.Config.SslHost);
            Assert.AreEqual(expectedSyncTimeout, redisConnection.Config.SyncTimeout);
            Assert.AreEqual(expectedTieBreakerKey, redisConnection.Config.TieBreaker);
            Assert.AreEqual(expectedVersion, redisConnection.Config.DefaultVersion.ToString());
            Assert.AreEqual(expectedWriteBuffer, redisConnection.Config.WriteBuffer);
        }
 public void TestInvalidSentinelConfig()
 {
     Assert.Throws <ObjectDefinitionStoreException>(() =>
     {
         ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 2);
     });
 }
Exemplo n.º 3
0
 public void TestMissingQueueNameTest()
 {
     Assert.Throws <ObjectDefinitionStoreException>(() =>
     {
         ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 2);
     });
 }
Exemplo n.º 4
0
 public void TestInvalidRetryRequeueAdviceWithRetryInterval()
 {
     Assert.Throws <ObjectDefinitionStoreException>(() =>
     {
         ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 3);
     });
 }
 public void TestWithAmbiguousConfiguration(int configId)
 {
     Assert.Throws <ObjectDefinitionStoreException>(() =>
     {
         ParserTestsHelper.LoadConfig(ConfigConventionPrefix, configId);
     });
 }
 public void TestWithMissingConnection()
 {
     Assert.Throws <ObjectDefinitionStoreException>(() =>
     {
         ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 5);
     });
 }
Exemplo n.º 7
0
 public void TestWithTypeMapperInlineAndRefAttribute()
 {
     Assert.Throws <ObjectDefinitionStoreException>(() =>
     {
         ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 3);
     });
 }
 public void TestTypeMapperConfigWithMissingKeys()
 {
     Assert.Throws <ObjectDefinitionStoreException>(() =>
     {
         ParserTestsHelper.LoadConfig(ConfgiConventionPrefix, 2);
     });
 }
Exemplo n.º 9
0
 public void TestWithConnectionStringAndSpecificOptions()
 {
     Assert.Throws <ObjectDefinitionStoreException>(() =>
     {
         var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 3);
     });
 }
 public void TestThatContainerMustHaveOneOrMoreChannels()
 {
     Assert.Throws <ObjectDefinitionStoreException>(() =>
     {
         ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 2);
     });
 }
 public void TestTypeMapperConfigWithUnresolvableTypes()
 {
     Assert.Throws <ObjectDefinitionStoreException>(() =>
     {
         ParserTestsHelper.LoadConfig(ConfgiConventionPrefix, 4);
     });
 }
 public void TestWithBrokenRefConnectionArg()
 {
     Assert.Throws <ObjectCreationException>(() =>
     {
         var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 4);
         objectFactory.GetObject <RedisQueueSentinel>("sentinel");
     });
 }
Exemplo n.º 13
0
        public void TestWithConnectionString()
        {
            var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 1);

            var redisConnection = objectFactory.GetObject <RedisConnection>("strongConnection");

            Assert.NotNull(redisConnection);
        }
        public void TestWithBrokenConnectionRefAttribute(int configId)
        {
            Assert.Throws <ObjectCreationException>(() =>
            {
                var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, configId);

                objectFactory.GetObject <RedisProducer>("myProducer");
            });
        }
Exemplo n.º 15
0
        public void TestWithTypeMapperAttributeBrokenRef()
        {
            Assert.Throws <ObjectCreationException>(() =>
            {
                var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 4);

                objectFactory.GetObject <JsonMessageConverter>("msgConverter");
            });
        }
Exemplo n.º 16
0
        public void TestDefenseAgainstBrokenRefs(int configId)
        {
            Assert.Throws <ObjectCreationException>(() =>
            {
                var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, configId);

                objectFactory.GetObject <RedisChannel>("myChannel");
            });
        }
Exemplo n.º 17
0
        public void TestDefaultErrorHandlerAutoAssignedWhenNoneConfigured()
        {
            var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 8);

            var channel = objectFactory.GetObject <RedisChannel>("myChannel");

            Assert.NotNull(channel);
            Assert.NotNull(channel.DefaultErrorHandler);
            Assert.IsInstanceOf <DeadLetterErrorHandler>(channel.DefaultErrorHandler);
        }
        public void TestWithInlineConfiguration()
        {
            var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 8);

            var producer = objectFactory.GetObject <RedisProducer>("myProducer");

            Assert.NotNull(producer);
            Assert.IsNotNull(producer.Connection);
            Assert.IsNotNull(producer.Queue);
        }
Exemplo n.º 19
0
        public void TestValidQueueConfig(int configId, string expectedQueueName, int expectedTtl)
        {
            var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, configId);

            var q = objectFactory.GetObject <RedisQueue>("queue1");

            Assert.NotNull(q);
            Assert.AreEqual(expectedQueueName, q.Name);
            Assert.AreEqual(expectedTtl, q.TTL);
        }
        public void TestLoadingValidSentinelConfig(int configId, int expectedMessageTimeout, int expectedInterval)
        {
            var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, configId);

            var sentinel = objectFactory.GetObject <RedisQueueSentinel>("sentinel");

            Assert.NotNull(sentinel);
            Assert.NotNull(sentinel.Connection);
            Assert.AreEqual(expectedMessageTimeout, sentinel.MessageTimeout);
            Assert.AreEqual(expectedInterval, sentinel.Interval);
        }
Exemplo n.º 21
0
        public void TestWithInlineTypeMapper()
        {
            const int expectedKnownTypesCount = 2;

            var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 2);

            var msgConverter = objectFactory.GetObject <JsonMessageConverter>("msgConverter");

            Assert.NotNull(msgConverter);
            Assert.IsTrue(msgConverter.CreateMessageIds);
            Assert.NotNull(msgConverter.TypeMapper);
            Assert.AreEqual(expectedKnownTypesCount, msgConverter.TypeMapper.Types.Count);
        }
        public void TestWithNoQueueProvided()
        {
            var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 2);

            var producer = objectFactory.GetObject <RedisProducer>("myProducer");

            var expectedConnection = objectFactory.GetObject <RedisConnection>("strongConnection");

            Assert.NotNull(producer);
            Assert.IsNotNull(producer.Connection);
            Assert.IsNull(producer.Queue);
            Assert.AreEqual(expectedConnection, producer.Connection);
        }
Exemplo n.º 23
0
        public void TestDefenseAgainstMissingRefs(int configId, string propertyName)
        {
            var exception = Assert.Throws <ObjectDefinitionStoreException>(() =>
            {
                var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, configId);

                objectFactory.GetObject <RedisChannel>("myChannel");
            });

            var attrName             = propertyName.ToCamelCase();
            var expectedErrorMessage = $"Either {attrName} attribute or the {attrName} element (but not both) should be defined.";

            Assert.AreEqual(expectedErrorMessage, exception.GetBaseException().Message);
        }
Exemplo n.º 24
0
        public void TestDefenseAgainstAmbiguousConfig(int configId, string propertyName)
        {
            var exception = Assert.Throws <ObjectDefinitionStoreException>(() =>
            {
                var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, configId);

                objectFactory.GetObject <RedisChannel>("myChannel");
            });

            var attrName             = propertyName.ToCamelCase();
            var expectedErrorMessage = $"The {attrName} attribute and the {attrName} element, both cannot be defined at the same time.";

            Assert.AreEqual(expectedErrorMessage, exception.GetBaseException().Message);
        }
        public void TestWithAttributeRefs()
        {
            var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 1);

            var producer = objectFactory.GetObject <RedisProducer>("myProducer");

            var expectedConnection = objectFactory.GetObject <RedisConnection>("strongConnection");
            var expectedQueue      = objectFactory.GetObject <RedisQueue>("myQueue");

            Assert.NotNull(producer);
            Assert.IsNotNull(producer.Connection);
            Assert.IsNotNull(producer.Queue);
            Assert.AreEqual(expectedConnection, producer.Connection);
            Assert.AreEqual(expectedQueue, producer.Queue);
        }
        public void TestWithValidConfig()
        {
            var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 1);

            var container = objectFactory.GetObject <RedisContainer>("myContainer");

            const int expectedChannelsCount = 1;
            var       expectedConnection    = objectFactory.GetObject <RedisConnection>("strongConnection");
            var       expectedSentinel      = objectFactory.GetObject <RedisQueueSentinel>("sentinel");

            Assert.NotNull(container);
            Assert.AreEqual(expectedChannelsCount, container.Channels.Count());
            Assert.AreEqual(expectedConnection, container.Connection);
            Assert.AreEqual(expectedSentinel, container.Sentinel);
            Assert.IsTrue(container.EnableSentinel);
        }
        public void TestTypeMapperWithValidConfig()
        {
            const int    expectedMapCount    = 2;
            var          basicMessageType    = typeof(BasicMessage);
            const string basicMessageTypeKey = "Basic";

            var objectFactory = ParserTestsHelper.LoadConfig(ConfgiConventionPrefix, 1);

            var mapper = objectFactory.GetObject <TypeMapper>("myTypeMapper");

            Assert.NotNull(mapper);
            Assert.AreEqual(expectedMapCount, mapper.Types.Count);

            var actualType = mapper.GetTypeForKey(basicMessageTypeKey);

            Assert.AreEqual(basicMessageType, actualType);
        }
Exemplo n.º 28
0
        public void TestRetryRequeueAdvice()
        {
            const bool       expectedRetryOnFail   = true;
            const AdviceType expectedAdviceType    = AdviceType.RetryRequeue;
            const string     expectedExceptionType = "System.Data.SqlClient.SqlException";
            var expectedTimeoutException           = typeof(SqlException);

            var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 1);

            var timedErrorAdvice = objectFactory.GetObject <ErrorAdvice>("advice2");

            Assert.NotNull(timedErrorAdvice);
            Assert.AreEqual(expectedRetryOnFail, timedErrorAdvice.RetryOnFail);
            Assert.AreEqual(expectedAdviceType, timedErrorAdvice.AdviceType);
            Assert.AreEqual(expectedExceptionType, timedErrorAdvice.ExceptionType);
            Assert.AreEqual(expectedTimeoutException, timedErrorAdvice.GetExceptionType());
        }
Exemplo n.º 29
0
        public void TestWithRefObjects()
        {
            var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 2);

            var channel = objectFactory.GetObject <RedisChannel>("myChannel");

            const int expectedConcurrency   = 5;
            const int expectedListenerCount = 1;

            Assert.NotNull(channel);
            Assert.NotNull(channel.MessageQueue);
            Assert.NotNull(channel.DeadLetterQueue);
            Assert.NotNull(channel.PoisonQueue);
            Assert.NotNull(channel.MessageConverter);
            Assert.NotNull(channel.DefaultErrorHandler);

            Assert.AreEqual(expectedConcurrency, channel.Concurrency);
            Assert.AreEqual(expectedListenerCount, channel.Listeners.Count());
        }
Exemplo n.º 30
0
        public void TestTimedRetryAdvice()
        {
            const bool       expectedRetryOnFail   = true;
            const AdviceType expectedAdviceType    = AdviceType.TimedRetry;
            const string     expectedExceptionType = "TimeoutException";
            var       expectedTimeoutException     = typeof(TimeoutException);
            const int expectedRetryCount           = 8;
            const int expectedRetryInterval        = 30;

            var objectFactory = ParserTestsHelper.LoadConfig(ConfigConventionPrefix, 1);

            var timedErrorAdvice = objectFactory.GetObject <ErrorAdvice>("advice1");

            Assert.NotNull(timedErrorAdvice);
            Assert.AreEqual(expectedRetryOnFail, timedErrorAdvice.RetryOnFail);
            Assert.AreEqual(expectedAdviceType, timedErrorAdvice.AdviceType);
            Assert.AreEqual(expectedExceptionType, timedErrorAdvice.ExceptionType);
            Assert.AreEqual(expectedTimeoutException, timedErrorAdvice.GetExceptionType());
            Assert.AreEqual(expectedRetryCount, timedErrorAdvice.RetryCount);
            Assert.AreEqual(expectedRetryInterval, timedErrorAdvice.RetryInterval);
        }