Example #1
0
        static SqlServerTransport GetTransport(TransportType transportType)
        {
            var rebusTime          = new DefaultRebusTime();
            var loggerFactory      = new ConsoleLoggerFactory(false);
            var connectionProvider = new DbConnectionProvider(SqlTestHelper.ConnectionString, loggerFactory);
            var asyncTaskFactory   = new TplAsyncTaskFactory(loggerFactory);

            var transport = transportType == TransportType.LeaseBased
                ? new SqlServerLeaseTransport(
                connectionProvider,
                QueueName,
                loggerFactory,
                asyncTaskFactory,
                rebusTime,
                TimeSpan.FromMinutes(1),
                TimeSpan.FromSeconds(5),
                () => "who cares",
                new SqlServerLeaseTransportOptions(connectionProvider)
                )
                : new SqlServerTransport(
                connectionProvider,
                QueueName,
                loggerFactory,
                asyncTaskFactory,
                rebusTime,
                new SqlServerTransportOptions(connectionProvider)
                );

            transport.EnsureTableIsCreated();
            transport.Initialize();

            return(transport);
        }
    SqlServerTransport GetTransport(string connectionString, IsolationLevel isolationLevel)
    {
        var rebusTime          = new DefaultRebusTime();
        var rebusLoggerFactory = new ConsoleLoggerFactory(false);

        var connectionProvider = new DbConnectionProvider(connectionString, rebusLoggerFactory)
        {
            IsolationLevel = isolationLevel
        };

        var taskFactory = new TplAsyncTaskFactory(rebusLoggerFactory);

        var transport = new SqlServerTransport(
            connectionProvider: connectionProvider,
            inputQueueName: _queueName,
            rebusLoggerFactory: rebusLoggerFactory,
            asyncTaskFactory: taskFactory,
            rebusTime: rebusTime,
            options: new SqlServerTransportOptions(connectionProvider)
            );

        transport.Initialize();

        return(transport);
    }
        public async Task DeliversMessagesByVisibleTimeAndNotByInsertionTime()
        {
            var rebusTime          = new DefaultRebusTime();
            var loggerFactory      = new ConsoleLoggerFactory(false);
            var connectionProvider = new DbConnectionProvider(MySqlTestHelper.ConnectionString, loggerFactory);
            var asyncTaskFactory   = new TplAsyncTaskFactory(loggerFactory);

            var transport = new MySqlTransport(
                connectionProvider,
                QueueName,
                loggerFactory,
                asyncTaskFactory,
                rebusTime,
                new MySqlTransportOptions(connectionProvider));

            transport.EnsureTableIsCreated();
            transport.Initialize();

            var now = DateTime.Now;

            await PutInQueue(transport, GetTransportMessage("first message"));
            await PutInQueue(transport, GetTransportMessage("second message", deferredUntilTime : now.AddMinutes(-1)));
            await PutInQueue(transport, GetTransportMessage("third message", deferredUntilTime : now.AddMinutes(-2)));

            var firstMessage = await ReceiveMessageBody(transport);

            var secondMessage = await ReceiveMessageBody(transport);

            var thirdMessage = await ReceiveMessageBody(transport);

            // expect messages to be received in reverse order because of their visible times
            Assert.That(firstMessage, Is.EqualTo("third message"));
            Assert.That(secondMessage, Is.EqualTo("second message"));
            Assert.That(thirdMessage, Is.EqualTo("first message"));
        }
    protected override void SetUp()
    {
        var rebusTime          = new DefaultRebusTime();
        var loggerFactory      = new ConsoleLoggerFactory(false);
        var connectionProvider = new DbConnectionProvider(SqlTestHelper.ConnectionString, loggerFactory);

        var tableName = TestConfig.GetName("data");

        SqlTestHelper.DropTable(tableName);

        _storage = new SqlServerDataBusStorage(connectionProvider, tableName, true, loggerFactory, rebusTime, 240);
        _storage.Initialize();
    }
Example #5
0
        public ITransport CreateOneWayClient()
        {
            var rebusTime            = new DefaultRebusTime();
            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var connectionProvider   = new DbConnectionProvider(SqlTestHelper.ConnectionString, consoleLoggerFactory);
            var asyncTaskFactory     = new TplAsyncTaskFactory(consoleLoggerFactory);
            var transport            = new SqlServerTransport(connectionProvider, null, consoleLoggerFactory, asyncTaskFactory, rebusTime, new SqlServerTransportOptions(connectionProvider));

            _disposables.Add(transport);

            transport.Initialize();

            return(transport);
        }
        protected override void SetUp()
        {
            MySqlTestHelper.DropAllTables();

            var rebusTime            = new DefaultRebusTime();
            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var connectionProvider   = new DbConnectionProvider(MySqlTestHelper.ConnectionString, consoleLoggerFactory);
            var asyncTaskFactory     = new TplAsyncTaskFactory(consoleLoggerFactory);

            _transport = new MySqlTransport(connectionProvider, QueueName, consoleLoggerFactory, asyncTaskFactory, rebusTime, new MySqlTransportOptions(connectionProvider));
            _transport.EnsureTableIsCreated();

            Using(_transport);

            _transport.Initialize();

            _cancellationToken = new CancellationTokenSource().Token;
        }
Example #7
0
        public async Task TestLockFunctions()
        {
            var rebusTime            = new DefaultRebusTime();
            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var connectionProvider   = new DbConnectionProvider(MySqlTestHelper.ConnectionString, consoleLoggerFactory);
            var asyncTaskFactory     = new TplAsyncTaskFactory(consoleLoggerFactory);

            // Create a MySQL locker
            var locker = new MySqlExclusiveAccessLock(connectionProvider, _lockTableName, consoleLoggerFactory, asyncTaskFactory, rebusTime, new MySqlExclusiveAccessLockOptions(connectionProvider));

            locker.EnsureTableIsCreated();

            // Try the check function which will return false initially
            const string lockName = "my_lock";
            var          result   = await locker.IsLockAcquiredAsync(lockName, CancellationToken.None);

            Assert.That(result, Is.False);

            // Get the lock once
            result = await locker.AcquireLockAsync(lockName, CancellationToken.None);

            Assert.That(result, Is.True);

            // Try to get it again, and it should fail
            result = await locker.AcquireLockAsync(lockName, CancellationToken.None);

            Assert.That(result, Is.False);

            // Try the check function
            result = await locker.IsLockAcquiredAsync(lockName, CancellationToken.None);

            Assert.That(result, Is.True);

            // Now release the lock
            await locker.ReleaseLockAsync(lockName);

            // Try the check function and it should be false now
            result = await locker.IsLockAcquiredAsync(lockName, CancellationToken.None);

            Assert.That(result, Is.False);
        }
Example #8
0
        public ITransport Create(string inputQueueAddress)
        {
            var tableName = ("RebusMessages_" + TestConfig.Suffix).TrimEnd('_');

            SqlTestHelper.DropTable(tableName);

            _tablesToDrop.Add(tableName);

            var rebusTime            = new DefaultRebusTime();
            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var connectionProvider   = new DbConnectionProvider(SqlTestHelper.ConnectionString, consoleLoggerFactory);
            var asyncTaskFactory     = new TplAsyncTaskFactory(consoleLoggerFactory);
            var transport            = new SqlServerTransport(connectionProvider, inputQueueAddress, consoleLoggerFactory, asyncTaskFactory, rebusTime, new SqlServerTransportOptions(connectionProvider));

            _disposables.Add(transport);

            transport.EnsureTableIsCreated();
            transport.Initialize();

            return(transport);
        }
Example #9
0
        public ITransport CreateOneWayClient()
        {
            var tableName = ("RebusMessages_" + TestConfig.Suffix).TrimEnd('_');

            SqlTestHelper.DropTable(tableName);

            _tablesToDrop.Add(tableName);

            var rebusTime            = new DefaultRebusTime();
            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var connectionProvider   = new DbConnectionProvider(SqlTestHelper.ConnectionString, consoleLoggerFactory);
            var asyncTaskFactory     = new TplAsyncTaskFactory(consoleLoggerFactory);
            var transport            = new SqlServerLeaseTransport(connectionProvider, null, consoleLoggerFactory,
                                                                   asyncTaskFactory, rebusTime, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(2), () => Environment.MachineName, new SqlServerLeaseTransportOptions(connectionProvider));

            _disposables.Add(transport);

            transport.Initialize();

            return(transport);
        }