Skip to content

Commit

Permalink
whitespace update
Browse files Browse the repository at this point in the history
  • Loading branch information
arnoldasgudas committed Jan 31, 2016
1 parent 7833afc commit 87a0927
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 148 deletions.
4 changes: 2 additions & 2 deletions Hangfire.MySql.Tests/CountersAggregatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class CountersAggregatorTests : IClassFixture<TestDatabaseFixture>
[Fact]
public void CountersAggregatorExecutesProperly()
{
const string createSql = @"
insert into Counter (`Key`, Value, ExpireAt)
const string createSql = @"
insert into Counter (`Key`, Value, ExpireAt)
values ('key', 1, @expireAt)";

using (var connection = CreateConnection())
Expand Down
84 changes: 42 additions & 42 deletions Hangfire.MySql.Tests/Utils/CleanDatabaseAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
using System.Reflection;
using System.Transactions;
using Xunit.Sdk;

namespace Hangfire.MySql.Tests
{
public class CleanDatabaseAttribute : BeforeAfterTestAttribute
{
private readonly IsolationLevel _isolationLevel;

private TransactionScope _transaction;

public CleanDatabaseAttribute(
IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
{
_isolationLevel = isolationLevel;
}

public override void Before(MethodInfo methodUnderTest)
{
if (_isolationLevel != IsolationLevel.Unspecified)
{
_transaction = new TransactionScope(
TransactionScopeOption.RequiresNew,
new TransactionOptions { IsolationLevel = _isolationLevel });
}
}

public override void After(MethodInfo methodUnderTest)
{
try
{
if (_transaction != null)
{
_transaction.Dispose();
}
}
finally
using System.Reflection;
using System.Transactions;
using Xunit.Sdk;

namespace Hangfire.MySql.Tests
{
public class CleanDatabaseAttribute : BeforeAfterTestAttribute
{
private readonly IsolationLevel _isolationLevel;

private TransactionScope _transaction;

public CleanDatabaseAttribute(
IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
{
_isolationLevel = isolationLevel;
}

public override void Before(MethodInfo methodUnderTest)
{
if (_isolationLevel != IsolationLevel.Unspecified)
{
}
}
}
}
_transaction = new TransactionScope(
TransactionScopeOption.RequiresNew,
new TransactionOptions { IsolationLevel = _isolationLevel });
}
}

public override void After(MethodInfo methodUnderTest)
{
try
{
if (_transaction != null)
{
_transaction.Dispose();
}
}
finally
{
}
}
}
}
102 changes: 51 additions & 51 deletions Hangfire.MySql.Tests/Utils/TestDatabaseFixture.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
using System;
using System.Threading;
using Dapper;
using MySql.Data.MySqlClient;

namespace Hangfire.MySql.Tests
{
public class TestDatabaseFixture : IDisposable
using System;
using System.Threading;
using Dapper;
using MySql.Data.MySqlClient;

namespace Hangfire.MySql.Tests
{
public class TestDatabaseFixture : IDisposable
{
private static readonly object GlobalLock = new object();
public TestDatabaseFixture()
private static readonly object GlobalLock = new object();
public TestDatabaseFixture()
{
Monitor.Enter(GlobalLock);
CreateAndInitializeDatabase();
}
public void Dispose()
{
Monitor.Enter(GlobalLock);
CreateAndInitializeDatabase();
}
public void Dispose()
{
DropDatabase();
Monitor.Exit(GlobalLock);
}

private static void CreateAndInitializeDatabase()
{
var recreateDatabaseSql = String.Format(
@"CREATE DATABASE IF NOT EXISTS `{0}`",
ConnectionUtils.GetDatabaseName());

using (var connection = new MySqlConnection(
ConnectionUtils.GetMasterConnectionString()))
{
connection.Execute(recreateDatabaseSql);
}

using (var connection = new MySqlConnection(
ConnectionUtils.GetConnectionString()))
{
MySqlObjectsInstaller.Install(connection);
}
}

private static void DropDatabase()
{
var recreateDatabaseSql = String.Format(
@"DROP DATABASE IF EXISTS `{0}`",
ConnectionUtils.GetDatabaseName());

using (var connection = new MySqlConnection(
ConnectionUtils.GetMasterConnectionString()))
{
connection.Execute(recreateDatabaseSql);
}
}
}
}
Monitor.Exit(GlobalLock);
}

private static void CreateAndInitializeDatabase()
{
var recreateDatabaseSql = String.Format(
@"CREATE DATABASE IF NOT EXISTS `{0}`",
ConnectionUtils.GetDatabaseName());

using (var connection = new MySqlConnection(
ConnectionUtils.GetMasterConnectionString()))
{
connection.Execute(recreateDatabaseSql);
}

using (var connection = new MySqlConnection(
ConnectionUtils.GetConnectionString()))
{
MySqlObjectsInstaller.Install(connection);
}
}

private static void DropDatabase()
{
var recreateDatabaseSql = String.Format(
@"DROP DATABASE IF EXISTS `{0}`",
ConnectionUtils.GetDatabaseName());

using (var connection = new MySqlConnection(
ConnectionUtils.GetMasterConnectionString()))
{
connection.Execute(recreateDatabaseSql);
}
}
}
}
106 changes: 53 additions & 53 deletions Hangfire.MySql/JobQueue/MySqlJobQueue.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
using System;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Threading;
using Dapper;
using Hangfire.Annotations;
using Hangfire.Logging;
using Hangfire.Storage;
using MySql.Data.MySqlClient;

namespace Hangfire.MySql.JobQueue
{
internal class MySqlJobQueue : IPersistentJobQueue
using System;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Threading;
using Dapper;
using Hangfire.Annotations;
using Hangfire.Logging;
using Hangfire.Storage;
using MySql.Data.MySqlClient;

namespace Hangfire.MySql.JobQueue
{
internal class MySqlJobQueue : IPersistentJobQueue
{
private static readonly ILog Logger = LogProvider.GetCurrentClassLogger();

private readonly MySqlStorage _storage;
private readonly MySqlStorageOptions _options;
public MySqlJobQueue(MySqlStorage storage, MySqlStorageOptions options)
private static readonly ILog Logger = LogProvider.GetCurrentClassLogger();

private readonly MySqlStorage _storage;
private readonly MySqlStorageOptions _options;
public MySqlJobQueue(MySqlStorage storage, MySqlStorageOptions options)
{
if (storage == null) throw new ArgumentNullException("storage");
if (options == null) throw new ArgumentNullException("options");

_storage = storage;
_options = options;
}

public IFetchedJob Dequeue(string[] queues, CancellationToken cancellationToken)
{
if (queues == null) throw new ArgumentNullException("queues");
if (queues.Length == 0) throw new ArgumentException("Queue array must be non-empty.", "queues");

FetchedJob fetchedJob = null;
MySqlConnection connection = null;
MySqlTransaction transaction = null;
if (options == null) throw new ArgumentNullException("options");

_storage = storage;
_options = options;
}

public IFetchedJob Dequeue(string[] queues, CancellationToken cancellationToken)
{
if (queues == null) throw new ArgumentNullException("queues");
if (queues.Length == 0) throw new ArgumentException("Queue array must be non-empty.", "queues");

FetchedJob fetchedJob = null;
MySqlConnection connection = null;
MySqlTransaction transaction = null;

string fetchJobSqlTemplate = @"
select Id, JobId, Queue
from JobQueue
where (FetchedAt is null or FetchedAt < DATE_ADD(UTC_TIMESTAMP(), INTERVAL @timeout SECOND))
string fetchJobSqlTemplate = @"
select Id, JobId, Queue
from JobQueue
where (FetchedAt is null or FetchedAt < DATE_ADD(UTC_TIMESTAMP(), INTERVAL @timeout SECOND))
and Queue in @queues
limit 1;
delete from JobQueue
where (FetchedAt is null or FetchedAt < DATE_ADD(UTC_TIMESTAMP(), INTERVAL @timeout SECOND))
limit 1;
delete from JobQueue
where (FetchedAt is null or FetchedAt < DATE_ADD(UTC_TIMESTAMP(), INTERVAL @timeout SECOND))
and Queue in @queues
limit 1";

Expand Down Expand Up @@ -84,21 +84,21 @@ and Queue in @queues
connection,
transaction,
fetchedJob.JobId.ToString(CultureInfo.InvariantCulture),
fetchedJob.Queue);
fetchedJob.Queue);
}

public void Enqueue(IDbConnection connection, string queue, string jobId)
public void Enqueue(IDbConnection connection, string queue, string jobId)
{
Logger.TraceFormat("Enqueue JobId={0} Queue={1}", jobId, queue);
connection.Execute("insert into JobQueue (JobId, Queue) values (@jobId, @queue)", new { jobId, queue });
}

[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
private class FetchedJob
{
public int Id { get; set; }
public int JobId { get; set; }
public string Queue { get; set; }
}
}
connection.Execute("insert into JobQueue (JobId, Queue) values (@jobId, @queue)", new { jobId, queue });
}

[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
private class FetchedJob
{
public int Id { get; set; }
public int JobId { get; set; }
public string Queue { get; set; }
}
}
}

0 comments on commit 87a0927

Please sign in to comment.