Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #109 from nathannis/master

Excessive Blacklisting when using a load balancer to access nodes
  • Loading branch information...
commit f83865b8a71c3758976c6dece58d8aba3f429567 2 parents 9ced334 + f575b66
@nberardi nberardi authored
View
2  src/Connections/ConnectionBuilder.cs
@@ -14,7 +14,7 @@ public class ConnectionBuilder : FluentCassandra.Connections.IConnectionBuilder
/// <param name="host"></param>
/// <param name="port"></param>
/// <param name="timeout"></param>
- public ConnectionBuilder(string keyspace, string host, int port = Server.DefaultPort, int connectionTimeout = Server.DefaultTimeout, bool pooling = false, int minPoolSize = 0, int maxPoolSize = 100, int maxRetries = 0, int serverPollingInterval = 30, int connectionLifetime = 0, ConnectionType connectionType = ConnectionType.Framed, int bufferSize = 1024, ConsistencyLevel read = ConsistencyLevel.QUORUM, ConsistencyLevel write = ConsistencyLevel.QUORUM, string cqlVersion = FluentCassandra.Connections.CqlVersion.ServerDefault, bool compressCqlQueries = true, string username = null, string password = null)
+ public ConnectionBuilder(string keyspace, string host, int port = Server.DefaultPort, int connectionTimeout = Server.DefaultTimeout, bool pooling = false, int minPoolSize = 0, int maxPoolSize = 100, int maxRetries = 0, int serverPollingInterval = 30, int connectionLifetime = 0, ConnectionType connectionType = ConnectionType.Framed, int bufferSize = 1024, ConsistencyLevel read = ConsistencyLevel.QUORUM, ConsistencyLevel write = ConsistencyLevel.QUORUM, string cqlVersion = FluentCassandra.Connections.CqlVersion.ConnectionDefault , bool compressCqlQueries = true, string username = null, string password = null)
{
Keyspace = keyspace;
Servers = new List<Server>() { new Server(host, port) };
View
2  src/Connections/ConnectionProvider.cs
@@ -11,7 +11,7 @@ public abstract class ConnectionProvider : IConnectionProvider
protected ConnectionProvider(IConnectionBuilder builder)
{
ConnectionBuilder = builder;
- Servers = new RoundRobinServerManager(builder);
+ Servers = new SingleServerManager(builder);
}
/// <summary>
View
63 src/Connections/SingleServerManager.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Diagnostics;
+
+namespace FluentCassandra.Connections
+{
+ public class SingleServerManager : IServerManager
+ {
+ private readonly object _lock = new object();
+ private Server _server;
+
+ public SingleServerManager(IConnectionBuilder builder)
+ {
+ _server = builder.Servers[0];
+ }
+
+ #region IServerManager Members
+
+ public bool HasNext
+ {
+ get { return true; }
+ }
+
+ public Server Next()
+ {
+ return _server;
+ }
+
+ public void ErrorOccurred(Server server, Exception exc = null)
+ {
+ Debug.WriteLineIf(exc != null, exc, "connection");
+ }
+
+ public void Add(Server server)
+ {
+ _server = server;
+ }
+ public void Remove(Server server)
+ {
+ throw new NotImplementedException ("SingleServerManager does not implement Remove(server)");
+ }
+ #endregion
+ #region IEnumerable<Server> Members
+
+ public IEnumerator<Server> GetEnumerator()
+ {
+ throw new NotImplementedException("SingleServerManager does not implement Enumerable(server)");
+ }
+
+ #endregion
+
+ #region IEnumerable Members
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ #endregion
+ }
+}
View
7 src/FluentCassandra.csproj
@@ -39,11 +39,10 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
- <SignAssembly>false</SignAssembly>
+ <SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
- <AssemblyOriginatorKeyFile>
- </AssemblyOriginatorKeyFile>
+ <AssemblyOriginatorKeyFile>fluentCassandra-me.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@@ -115,6 +114,7 @@
<Compile Include="Connections\ConnectionType.cs" />
<Compile Include="Connections\CqlVersion.cs" />
<Compile Include="Connections\IConnectionBuilder.cs" />
+ <Compile Include="Connections\SingleServerManager.cs" />
<Compile Include="Connections\NormalConnectionProvider.cs" />
<Compile Include="Connections\IConnection.cs" />
<Compile Include="Connections\IConnectionProvider.cs" />
@@ -312,6 +312,7 @@
<Compile Include="Types\VoidType.cs" />
</ItemGroup>
<ItemGroup>
+ <None Include="fluentCassandra-me.snk" />
<None Include="FluentCassandra.nuspec">
<SubType>Designer</SubType>
</None>
View
4 test/FluentCassandra.StressTest/Main.cs
@@ -5,14 +5,14 @@
namespace FluentCassandra.StressTest
{
- class Program
+ class Program1
{
static void Main(string[] args)
{
Console.Error.WriteLine("Stress Test 1");
try
{
- StressTest.StressTest1.Test();
+ //tressTest1.Test();
}
catch (Exception ex)
{
View
2  test/FluentCassandra.StressTest/StressTest1.cs
@@ -4,7 +4,7 @@
using System.Threading.Tasks;
using FluentCassandra.Types;
using FluentCassandra.Connections;
-using Apache.Cassandra;
+using FluentCassandra.Apache.Cassandra;
namespace FluentCassandra.StressTest
{
View
27 test/FluentCassandra.Tests/Connections/SingleServerManagerTests.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using Xunit;
+
+namespace FluentCassandra.Connections.Tests
+{
+ public class SingleServerManagerTests
+ {
+ [Fact]
+ public void CanGetServerAfterError()
+ {
+ SingleServerManager target = new SingleServerManager(new ConnectionBuilder("Server=unit-test-1"));
+
+ Server original = target.Next();
+
+ for (int i = 0; i < 10; i++)
+ {
+ Assert.True(target.HasNext, "SingleServerManager should always have another server available.");
+ Server next = target.Next();
+ Assert.True(original.ToString().Equals(next.ToString(), StringComparison.OrdinalIgnoreCase),
+ "SingleServerManager always returns the same server.");
+ //mark the server as failing to set up the next test iteration.
+ target.ErrorOccurred(next);
+ }
+ }
+ }
+}
View
1  test/FluentCassandra.Tests/FluentCassandra.Tests.csproj
@@ -61,6 +61,7 @@
<Compile Include="CassandraQueryTest.cs" />
<Compile Include="Connections\ConnectionBuilderTests.cs" />
<Compile Include="Connections\ConnectionProviderTests.cs" />
+ <Compile Include="Connections\SingleServerManagerTests.cs" />
<Compile Include="Connections\NormalConnectionProviderTests.cs" />
<Compile Include="Connections\RoundRobinServerManagerTests.cs" />
<Compile Include="CqlHelperTest.cs" />
View
2  test/FluentCassandra.Tests/app.config
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
- <add key="TestServer" value="localhost"></add>
+ <add key="TestServer" value="dev-Cassandra"></add>
<add key="TestPort" value="9160"></add>
<add key="TestKeySpace" value="Testing"></add>
</appSettings>
Please sign in to comment.
Something went wrong with that request. Please try again.