Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixing tabs

  • Loading branch information...
commit 8b29440773ec7367e163c2df1abd803c7924ab32 1 parent bf0bed5
Arne Claassen sdether authored
2  src/Connections/InfallibleSingleServerManager.cs
View
@@ -8,7 +8,7 @@ public class InfallibleSingleServerManager : IServerManager
{
private Server _server;
- public InfallibleSingleServerManager(IConnectionBuilder builder)
+ public InfallibleSingleServerManager(IConnectionBuilder builder)
{
_server = builder.Servers[0];
}
72 src/Connections/ServerManagerFactory.cs
View
@@ -3,46 +3,46 @@
namespace FluentCassandra.Connections
{
- public static class ServerManagerFactory
- {
- private static readonly object LOCK = new object();
- private static volatile IDictionary<string, IServerManager> _managers = new Dictionary<string, IServerManager>();
- private static volatile Func<IConnectionBuilder, IServerManager> _alternateManagerCreator;
+ public static class ServerManagerFactory
+ {
+ private static readonly object LOCK = new object();
+ private static volatile IDictionary<string, IServerManager> _managers = new Dictionary<string, IServerManager>();
+ private static volatile Func<IConnectionBuilder, IServerManager> _alternateManagerCreator;
- public static IServerManager Get(IConnectionBuilder connectionBuilder)
- {
- lock(LOCK)
- {
- IServerManager manager;
+ public static IServerManager Get(IConnectionBuilder connectionBuilder)
+ {
+ lock(LOCK)
+ {
+ IServerManager manager;
- if(!_managers.TryGetValue(connectionBuilder.Uuid, out manager))
- {
- manager = CreateManager(connectionBuilder);
- _managers.Add(connectionBuilder.Uuid, manager);
- }
+ if(!_managers.TryGetValue(connectionBuilder.Uuid, out manager))
+ {
+ manager = CreateManager(connectionBuilder);
+ _managers.Add(connectionBuilder.Uuid, manager);
+ }
- return manager;
- }
- }
+ return manager;
+ }
+ }
- public static void SetAlternateManagerCreationCallback(Func<IConnectionBuilder, IServerManager> alternateManagerCreator)
- {
- lock(LOCK)
- _alternateManagerCreator = alternateManagerCreator;
- }
+ public static void SetAlternateManagerCreationCallback(Func<IConnectionBuilder, IServerManager> alternateManagerCreator)
+ {
+ lock(LOCK)
+ _alternateManagerCreator = alternateManagerCreator;
+ }
- private static IServerManager CreateManager(IConnectionBuilder builder)
- {
- if(_alternateManagerCreator != null)
- {
- var manager = _alternateManagerCreator(builder);
- if(manager != null)
- return manager;
- }
+ private static IServerManager CreateManager(IConnectionBuilder builder)
+ {
+ if(_alternateManagerCreator != null)
+ {
+ var manager = _alternateManagerCreator(builder);
+ if(manager != null)
+ return manager;
+ }
- return builder.Servers.Count == 1
- ? (IServerManager)new SingleServerManager(builder)
- : new RoundRobinServerManager(builder);
- }
- }
+ return builder.Servers.Count == 1
+ ? (IServerManager)new SingleServerManager(builder)
+ : new RoundRobinServerManager(builder);
+ }
+ }
}
86 src/Connections/SingleServerManager.cs
View
@@ -8,42 +8,42 @@ namespace FluentCassandra.Connections
public class SingleServerManager : IServerManager
{
private readonly object _lock = new object();
- private readonly Timer _recoveryTimer;
- private readonly long _recoveryTimerInterval;
- private Server _server;
- private bool _failed;
+ private readonly Timer _recoveryTimer;
+ private readonly long _recoveryTimerInterval;
+ private Server _server;
+ private bool _failed;
public SingleServerManager(IConnectionBuilder builder)
{
_server = builder.Servers[0];
- _recoveryTimerInterval = (long)builder.ServerPollingInterval.TotalMilliseconds;
- _recoveryTimer = new Timer(ServerRecover);
- }
+ _recoveryTimerInterval = (long)builder.ServerPollingInterval.TotalMilliseconds;
+ _recoveryTimer = new Timer(ServerRecover);
+ }
- private void ServerRecover(object unused)
- {
- lock(_lock)
- {
- if(!_failed)
- return;
+ private void ServerRecover(object unused)
+ {
+ lock(_lock)
+ {
+ if(!_failed)
+ return;
- var connection = new Connection(_server, ConnectionType.Simple, 1024);
+ var connection = new Connection(_server, ConnectionType.Simple, 1024);
- try
- {
- connection.Open();
- _failed = false;
- }
- catch { }
- finally
- {
- connection.Close();
- }
- }
- }
+ try
+ {
+ connection.Open();
+ _failed = false;
+ }
+ catch { }
+ finally
+ {
+ connection.Close();
+ }
+ }
+ }
- #region IServerManager Members
+ #region IServerManager Members
public bool HasNext
{
@@ -56,27 +56,27 @@ public Server Next()
}
public void ErrorOccurred(Server server, Exception exc = null)
- {
+ {
Debug.WriteLineIf(exc != null, exc, "connection");
- lock(_lock)
- {
- if(_failed)
- return;
+ lock(_lock)
+ {
+ if(_failed)
+ return;
- _failed = true;
- _recoveryTimer.Change(_recoveryTimerInterval, Timeout.Infinite);
- }
- }
+ _failed = true;
+ _recoveryTimer.Change(_recoveryTimerInterval, Timeout.Infinite);
+ }
+ }
public void Add(Server server)
{
- lock(_lock)
- {
- _server = server;
- _failed = false;
- _recoveryTimer.Change(Timeout.Infinite,Timeout.Infinite);
- }
- }
+ lock(_lock)
+ {
+ _server = server;
+ _failed = false;
+ _recoveryTimer.Change(Timeout.Infinite,Timeout.Infinite);
+ }
+ }
public void Remove(Server server)
{
6 test/FluentCassandra.Tests/Connections/InfallibleSingleServerManagerTests.cs
View
@@ -3,7 +3,7 @@
namespace FluentCassandra.Connections
{
- public class InfallibleSingleServerManagerTests
+ public class InfallibleSingleServerManagerTests
{
[Fact]
public void CanGetServerAfterError()
@@ -14,10 +14,10 @@ public void CanGetServerAfterError()
for (int i = 0; i < 10; i++)
{
- Assert.True(target.HasNext, "InfallibleSingleServerManager should always have another server available.");
+ Assert.True(target.HasNext, "InfallibleSingleServerManager should always have another server available.");
Server next = target.Next();
- Assert.True(original.ToString().Equals(next.ToString(), StringComparison.OrdinalIgnoreCase), "InfallibleSingleServerManager always returns the same server.");
+ Assert.True(original.ToString().Equals(next.ToString(), StringComparison.OrdinalIgnoreCase), "InfallibleSingleServerManager always returns the same server.");
//mark the server as failing to set up the next test iteration.
target.ErrorOccurred(next);
146 test/FluentCassandra.Tests/Connections/ServerManagerFactoryTests.cs
View
@@ -5,88 +5,88 @@
namespace FluentCassandra.Connections
{
- public class ServerManagerFactoryTests
- {
+ public class ServerManagerFactoryTests
+ {
- // Make sure these tests never run in parallel (in case someone uses a parallel test runner),
- // since they both manipulate global state of a singleton
- private static readonly object _lock = new object();
+ // Make sure these tests never run in parallel (in case someone uses a parallel test runner),
+ // since they both manipulate global state of a singleton
+ private static readonly object _lock = new object();
- [Fact]
- public void Can_insert_a_server_manager_creator()
- {
- lock(_lock)
- {
- try
- {
- ServerManagerFactory.SetAlternateManagerCreationCallback(b => new StubServerManager());
- var manager = ServerManagerFactory.Get(new ConnectionBuilder("Server=unit-test-1111"));
+ [Fact]
+ public void Can_insert_a_server_manager_creator()
+ {
+ lock(_lock)
+ {
+ try
+ {
+ ServerManagerFactory.SetAlternateManagerCreationCallback(b => new StubServerManager());
+ var manager = ServerManagerFactory.Get(new ConnectionBuilder("Server=unit-test-1111"));
- Assert.IsType<StubServerManager>(manager);
- }
- finally
- {
- ServerManagerFactory.SetAlternateManagerCreationCallback(null);
- }
- }
- }
+ Assert.IsType<StubServerManager>(manager);
+ }
+ finally
+ {
+ ServerManagerFactory.SetAlternateManagerCreationCallback(null);
+ }
+ }
+ }
- [Fact]
- public void Manager_creator_can_be_optional()
- {
- lock(_lock)
- {
- try
- {
- ServerManagerFactory.SetAlternateManagerCreationCallback(
- b => b.Servers[0].Host == "unit-test-2222b" ? new StubServerManager() : null
- );
- var manager1 = ServerManagerFactory.Get(new ConnectionBuilder("Server=unit-test-2222a"));
- var manager2 = ServerManagerFactory.Get(new ConnectionBuilder("Server=unit-test-2222b"));
+ [Fact]
+ public void Manager_creator_can_be_optional()
+ {
+ lock(_lock)
+ {
+ try
+ {
+ ServerManagerFactory.SetAlternateManagerCreationCallback(
+ b => b.Servers[0].Host == "unit-test-2222b" ? new StubServerManager() : null
+ );
+ var manager1 = ServerManagerFactory.Get(new ConnectionBuilder("Server=unit-test-2222a"));
+ var manager2 = ServerManagerFactory.Get(new ConnectionBuilder("Server=unit-test-2222b"));
- Assert.IsType<SingleServerManager>(manager1);
- Assert.IsType<StubServerManager>(manager2);
- }
- finally
- {
- ServerManagerFactory.SetAlternateManagerCreationCallback(null);
- }
- }
- }
+ Assert.IsType<SingleServerManager>(manager1);
+ Assert.IsType<StubServerManager>(manager2);
+ }
+ finally
+ {
+ ServerManagerFactory.SetAlternateManagerCreationCallback(null);
+ }
+ }
+ }
- public class StubServerManager : IServerManager
- {
- public IEnumerator<Server> GetEnumerator()
- {
- throw new NotImplementedException();
- }
+ public class StubServerManager : IServerManager
+ {
+ public IEnumerator<Server> GetEnumerator()
+ {
+ throw new NotImplementedException();
+ }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
- public bool HasNext { get; private set; }
-
- public Server Next()
- {
- throw new NotImplementedException();
- }
+ public bool HasNext { get; private set; }
+
+ public Server Next()
+ {
+ throw new NotImplementedException();
+ }
- public void ErrorOccurred(Server server, Exception exc = null)
- {
- throw new NotImplementedException();
- }
+ public void ErrorOccurred(Server server, Exception exc = null)
+ {
+ throw new NotImplementedException();
+ }
- public void Add(Server server)
- {
- throw new NotImplementedException();
- }
+ public void Add(Server server)
+ {
+ throw new NotImplementedException();
+ }
- public void Remove(Server server)
- {
- throw new NotImplementedException();
- }
- }
- }
+ public void Remove(Server server)
+ {
+ throw new NotImplementedException();
+ }
+ }
+ }
}
28 test/FluentCassandra.Tests/Connections/SingleServerManagerTests.cs
View
@@ -4,20 +4,20 @@
namespace FluentCassandra.Connections
{
- public class SingleServerManagerTests
- {
-
- [Fact]
- public void HasNextIsFalseAfterServerFailure()
- {
+ public class SingleServerManagerTests
+ {
+
+ [Fact]
+ public void HasNextIsFalseAfterServerFailure()
+ {
- var manager = new SingleServerManager(new ConnectionBuilder("Server=unit-test-1"));
-
- Assert.True(manager.HasNext, "SingleServerManager was not initialized with a server");
- var server = manager.Next();
- manager.ErrorOccurred(server,new Exception());
+ var manager = new SingleServerManager(new ConnectionBuilder("Server=unit-test-1"));
+
+ Assert.True(manager.HasNext, "SingleServerManager was not initialized with a server");
+ var server = manager.Next();
+ manager.ErrorOccurred(server,new Exception());
- Assert.False(manager.HasNext, "SingleServerManager still has a server after its failure");
- }
- }
+ Assert.False(manager.HasNext, "SingleServerManager still has a server after its failure");
+ }
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.