Skip to content

Commit

Permalink
Trying to replicate issue with get_slice_range using raw thrift, same…
Browse files Browse the repository at this point in the history
… result. "start key's md5 sorts after end key's md5. this is not allowed; you probably should not specify end key at all, under RandomPartitioner"
  • Loading branch information
Kris Williams committed Apr 30, 2010
1 parent bb9e3ff commit 565c87e
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 38 deletions.
1 change: 1 addition & 0 deletions Test/HectorSharp.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<Compile Include="CassandraRunnerShould.cs" />
<Compile Include="KeySpaceShould.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RawThriftFixture.cs" />
<Compile Include="RawThriftShould.cs" />
<Compile Include="TestFixture.cs" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Test/HectorSharp.Test.dotnet35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<Compile Include="CassandraRunnerShould.cs" />
<Compile Include="KeySpaceShould.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RawThriftFixture.cs" />
<Compile Include="RawThriftShould.cs" />
<Compile Include="TestFixture.cs" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Test/KeySpaceShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace HectorSharp.Test
{
public class KeySpaceShould : IUseFixture<TestFixture>
public class KeySpaceShould : IUseFixture<HectorSharpFixture>
{
ICassandraClient Client { get { return fixture.Client; } }
IKeyspace Keyspace { get { return fixture.Keyspace; } }
Expand Down Expand Up @@ -595,9 +595,9 @@ public void Failover()

#region IUseFixture<CassandraTestFixture> Members

TestFixture fixture;
HectorSharpFixture fixture;

public void SetFixture(TestFixture fixture)
public void SetFixture(HectorSharpFixture fixture)
{
this.fixture = fixture;
}
Expand Down
72 changes: 72 additions & 0 deletions Test/RawThriftFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Thrift.Transport;
using Xunit;
using Thrift.Protocol;
using Apache.Cassandra;

namespace Test
{
using CassandraRunner = HectorSharp.Test.CassandraRunner;

public class RawThriftFixture : IDisposable
{
TTransport transport = new TSocket("localhost", 9060);
Cassandra.Client client;
public Cassandra.Client Client { get { return client;} }

public RawThriftFixture()
{
client = new Cassandra.Client(new TBinaryProtocol(transport));
}

public void OpenConnection()
{
if (!transport.IsOpen)
{
Console.WriteLine("Opening Connection");
transport.Open();
}
Assert.True(transport.IsOpen);
}

public void CloseConnection()
{
if (transport.IsOpen)
{
Console.WriteLine("Closing Connection");
transport.Close();
}
Assert.False(transport.IsOpen);
}

public void RestartCassandra()
{
if (CassandraRunner.Running)
CassandraRunner.Stop();
CassandraRunner.CleanData();
CassandraRunner.Start();
Assert.True(CassandraRunner.Running);
}

public void StopCassandra()
{
if (CassandraRunner.Running)
CassandraRunner.Stop();
Assert.False(CassandraRunner.Running);
}

#region IDisposable Members

public void Dispose()
{
CloseConnection();
CassandraRunner.Stop();
CassandraRunner.CleanData();
}

#endregion
}
}
108 changes: 75 additions & 33 deletions Test/RawThriftShould.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,77 @@
using System;
using System.Collections.Generic;
using Apache.Cassandra;
using Thrift.Protocol;
using Thrift.Transport;
using Xunit;

namespace Test
{
using CassandraRunner = HectorSharp.Test.CassandraRunner;
using ConsistencyLevel = Apache.Cassandra.ConsistencyLevel;

/// <summary>
/// Tests thrift-generated Cassandra classes and Thrift directly
/// These are integration tests and require cassandra running locally,
/// listening to thrift at port 9160
/// </summary>
public class RawThriftShould
public class RawThriftShould : IUseFixture<RawThriftFixture>
{
[Fact]
public void GetRangeSlice()
{
env.RestartCassandra();
env.OpenConnection();

var cf = "Standard2";
for (int i = 0; i < 10; i++)
{
var cp = new ColumnPath(cf);
cp.Column = ("testGetRangeSlice" + i).UTF();

client.insert(
"Keyspace1",
"GetRangeSlice.0", cp,
("GetRangeSlice.value." + i).UTF(),
HectorSharp.Util.UnixTimestamp,
ConsistencyLevel.ONE);

client.insert(
"Keyspace1",
"GetRangeSlice.1", cp,
("GetRangeSlice.value." + i).UTF(),
HectorSharp.Util.UnixTimestamp,
ConsistencyLevel.ONE);

client.insert(
"Keyspace1",
"GetRangeSlice.2", cp,
("GetRangeSlice.value." + i).UTF(),
HectorSharp.Util.UnixTimestamp,
ConsistencyLevel.ONE);
}

var columnParent = new ColumnParent(cf);
var predicate = new SlicePredicate(new SliceRange(false, 150));

var keySlices = client.get_range_slice(
"Keyspace1", columnParent, predicate,
"testGetRangeSlice0", "testGetRangeSlice3", 5, ConsistencyLevel.ONE);

Assert.NotNull(keySlices);
Assert.Equal(3, keySlices.Count);
//Assert.NotNull(keySlices["GetRangeSlice.0"]);
//Assert.Equal("GetRangeSlice.value.0", keySlices["GetRangeSlice.0"].First().Value);
//Assert.Equal(10, keySlices["GetRangeSlice.1"].Count);

env.CloseConnection();
env.StopCassandra();
}


/// <summary>
/// Adapted from sample code at: http://it.toolbox.com/people/joshschulz/journal-entry/4691
/// </summary>
[Fact]
public void SimpleScenario()
{
CassandraRunner.CleanData();
CassandraRunner.Start();

TTransport transport = new TSocket("localhost", 9060);
TProtocol protocol = new TBinaryProtocol(transport);
var client = new Cassandra.Client(protocol);

Console.WriteLine("Opening Connection");
transport.Open();
env.RestartCassandra();
env.OpenConnection();

//At this point we're using the standard configuration file
var nameColumnPath = new ColumnPath("Standard1", null, "name");
Expand Down Expand Up @@ -90,25 +130,15 @@ public void SimpleScenario()
}
}

Console.WriteLine("closing connection");
transport.Close();

CassandraRunner.Stop();
CassandraRunner.CleanData();
env.CloseConnection();
env.StopCassandra();
}

[Fact]
public void BlogModelScenario()
{
CassandraRunner.CleanData();
CassandraRunner.Start();

TTransport transport = new TSocket("localhost", 9060);
TProtocol protocol = new TBinaryProtocol(transport);
var client = new Cassandra.Client(protocol);

Console.WriteLine("Opening Connection");
transport.Open();
env.RestartCassandra();
env.OpenConnection();

string entryTitle = "now with bonus batch writes";
string entryAuthor = "josh";
Expand Down Expand Up @@ -142,11 +172,23 @@ public void BlogModelScenario()
column.Name.UTFDecode(),
column.Value.UTFDecode());
}
Console.WriteLine("closing connection");
transport.Close();

CassandraRunner.Stop();
CassandraRunner.CleanData();
env.CloseConnection();
env.StopCassandra();
}


#region IUseFixture<RawThriftFixture> Members

RawThriftFixture env;
Cassandra.Client client;

public void SetFixture(RawThriftFixture fixture)
{
env = fixture;
client = env.Client;
}

#endregion
}
}
4 changes: 2 additions & 2 deletions Test/TestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

namespace HectorSharp.Test
{
public class TestFixture : IDisposable
public class HectorSharpFixture : IDisposable
{
internal ICassandraClient Client;
internal IKeyspace Keyspace;
internal IKeyedObjectPool<Endpoint, ICassandraClient> Pool;

public TestFixture()
public HectorSharpFixture()
{
CassandraRunner.CleanData();
CassandraRunner.Start();
Expand Down

0 comments on commit 565c87e

Please sign in to comment.