Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix whitespace

commit 6e7d2013285db00f233f8b6d855b9c4bcb83d2f5 1 parent 7e51ee0
@mythz mythz authored
View
326 tests/ServiceStack.Redis.Tests/RedisPipelineTests.cs
@@ -5,11 +5,11 @@
namespace ServiceStack.Redis.Tests
{
- [TestFixture]
- public class RedisPipelineTests
- : RedisClientTestsBase
- {
- private const string Key = "pipemultitest";
+ [TestFixture]
+ public class RedisPipelineTests
+ : RedisClientTestsBase
+ {
+ private const string Key = "pipemultitest";
private const string ListKey = "pipemultitest-list";
private const string SetKey = "pipemultitest-set";
private const string SortedSetKey = "pipemultitest-sortedset";
@@ -20,66 +20,66 @@ public override void TearDown()
base.TearDown();
}
- [Test]
- public void Can_call_single_operation_in_pipeline()
- {
- Assert.That(Redis.GetValue(Key), Is.Null);
- using (var pipeline = Redis.CreatePipeline())
- {
- pipeline.QueueCommand(r => r.IncrementValue(Key));
- var map = new Dictionary<string, int>();
- pipeline.QueueCommand(r => r.Get<int>(Key), y => map[Key] = y);
-
- pipeline.Flush();
- }
-
- Assert.That(Redis.GetValue(Key), Is.EqualTo("1"));
- }
-
- [Test]
- public void No_commit_of_atomic_pipelines_discards_all_commands()
- {
- Assert.That(Redis.GetValue(Key), Is.Null);
- using (var pipeline = Redis.CreatePipeline())
- {
- pipeline.QueueCommand(r => r.IncrementValue(Key));
- }
- Assert.That(Redis.GetValue(Key), Is.Null);
- }
-
- [Test]
- public void Exception_in_atomic_pipelines_discards_all_commands()
- {
- Assert.That(Redis.GetValue(Key), Is.Null);
- try
- {
- using (var pipeline = Redis.CreatePipeline())
- {
- pipeline.QueueCommand(r => r.IncrementValue(Key));
- throw new NotSupportedException();
- }
- }
- catch (NotSupportedException ignore)
- {
- Assert.That(Redis.GetValue(Key), Is.Null);
- }
- }
-
- [Test]
- public void Can_call_single_operation_3_Times_in_pipeline()
- {
- Assert.That(Redis.GetValue(Key), Is.Null);
- using (var pipeline = Redis.CreatePipeline())
- {
- pipeline.QueueCommand(r => r.IncrementValue(Key));
- pipeline.QueueCommand(r => r.IncrementValue(Key));
- pipeline.QueueCommand(r => r.IncrementValue(Key));
-
- pipeline.Flush();
- }
-
- Assert.That(Redis.GetValue(Key), Is.EqualTo("3"));
- }
+ [Test]
+ public void Can_call_single_operation_in_pipeline()
+ {
+ Assert.That(Redis.GetValue(Key), Is.Null);
+ using (var pipeline = Redis.CreatePipeline())
+ {
+ pipeline.QueueCommand(r => r.IncrementValue(Key));
+ var map = new Dictionary<string, int>();
+ pipeline.QueueCommand(r => r.Get<int>(Key), y => map[Key] = y);
+
+ pipeline.Flush();
+ }
+
+ Assert.That(Redis.GetValue(Key), Is.EqualTo("1"));
+ }
+
+ [Test]
+ public void No_commit_of_atomic_pipelines_discards_all_commands()
+ {
+ Assert.That(Redis.GetValue(Key), Is.Null);
+ using (var pipeline = Redis.CreatePipeline())
+ {
+ pipeline.QueueCommand(r => r.IncrementValue(Key));
+ }
+ Assert.That(Redis.GetValue(Key), Is.Null);
+ }
+
+ [Test]
+ public void Exception_in_atomic_pipelines_discards_all_commands()
+ {
+ Assert.That(Redis.GetValue(Key), Is.Null);
+ try
+ {
+ using (var pipeline = Redis.CreatePipeline())
+ {
+ pipeline.QueueCommand(r => r.IncrementValue(Key));
+ throw new NotSupportedException();
+ }
+ }
+ catch (NotSupportedException ignore)
+ {
+ Assert.That(Redis.GetValue(Key), Is.Null);
+ }
+ }
+
+ [Test]
+ public void Can_call_single_operation_3_Times_in_pipeline()
+ {
+ Assert.That(Redis.GetValue(Key), Is.Null);
+ using (var pipeline = Redis.CreatePipeline())
+ {
+ pipeline.QueueCommand(r => r.IncrementValue(Key));
+ pipeline.QueueCommand(r => r.IncrementValue(Key));
+ pipeline.QueueCommand(r => r.IncrementValue(Key));
+
+ pipeline.Flush();
+ }
+
+ Assert.That(Redis.GetValue(Key), Is.EqualTo("3"));
+ }
[Test]
public void Can_call_hash_operations_in_pipeline()
{
@@ -100,11 +100,11 @@ public void Can_call_hash_operations_in_pipeline()
}
byte[][] members = null;
var pipeline = Redis.CreatePipeline();
-
-
+
+
pipeline.QueueCommand(r => ((RedisNativeClient)r).HMSet(Key, fieldBytes, valueBytes));
pipeline.QueueCommand(r => ((RedisNativeClient)r).HGetAll(Key), x => members = x);
-
+
pipeline.Flush();
@@ -122,11 +122,11 @@ public void Can_call_hash_operations_in_pipeline()
public void Can_call_multiple_setexs_in_pipeline()
{
Assert.That(Redis.GetValue(Key), Is.Null);
- var keys = new[] {Key + "key1", Key + "key2", Key + "key3"};
- var values = new[] { "1","2","3" };
+ var keys = new[] { Key + "key1", Key + "key2", Key + "key3" };
+ var values = new[] { "1", "2", "3" };
var pipeline = Redis.CreatePipeline();
-
- for (int i = 0; i < 3; ++i )
+
+ for (int i = 0; i < 3; ++i)
{
int index0 = i;
pipeline.QueueCommand(r => ((RedisNativeClient)r).SetEx(keys[index0], 100, GetBytes(values[index0])));
@@ -134,92 +134,92 @@ public void Can_call_multiple_setexs_in_pipeline()
pipeline.Flush();
pipeline.Replay();
-
-
- for (int i = 0; i < 3; ++i )
+
+
+ for (int i = 0; i < 3; ++i)
Assert.AreEqual(Redis.GetValue(keys[i]), values[i]);
pipeline.Dispose();
}
- [Test]
- public void Can_call_single_operation_with_callback_3_Times_in_pipeline()
- {
- var results = new List<long>();
- Assert.That(Redis.GetValue(Key), Is.Null);
- using (var pipeline = Redis.CreatePipeline())
- {
- pipeline.QueueCommand(r => r.IncrementValue(Key), results.Add);
- pipeline.QueueCommand(r => r.IncrementValue(Key), results.Add);
- pipeline.QueueCommand(r => r.IncrementValue(Key), results.Add);
-
- pipeline.Flush();
- }
-
- Assert.That(Redis.GetValue(Key), Is.EqualTo("3"));
- Assert.That(results, Is.EquivalentTo(new List<long> { 1, 2, 3 }));
- }
-
- [Test]
- public void Supports_different_operation_types_in_same_pipeline()
- {
- var incrementResults = new List<long>();
- var collectionCounts = new List<long>();
- var containsItem = false;
-
- Assert.That(Redis.GetValue(Key), Is.Null);
- using (var pipeline = Redis.CreatePipeline())
- {
- pipeline.QueueCommand(r => r.IncrementValue(Key), intResult => incrementResults.Add(intResult));
- pipeline.QueueCommand(r => r.AddItemToList(ListKey, "listitem1"));
- pipeline.QueueCommand(r => r.AddItemToList(ListKey, "listitem2"));
- pipeline.QueueCommand(r => r.AddItemToSet(SetKey, "setitem"));
- pipeline.QueueCommand(r => r.SetContainsItem(SetKey, "setitem"), b => containsItem = b);
- pipeline.QueueCommand(r => r.AddItemToSortedSet(SortedSetKey, "sortedsetitem1"));
- pipeline.QueueCommand(r => r.AddItemToSortedSet(SortedSetKey, "sortedsetitem2"));
- pipeline.QueueCommand(r => r.AddItemToSortedSet(SortedSetKey, "sortedsetitem3"));
- pipeline.QueueCommand(r => r.GetListCount(ListKey), intResult => collectionCounts.Add(intResult));
- pipeline.QueueCommand(r => r.GetSetCount(SetKey), intResult => collectionCounts.Add(intResult));
- pipeline.QueueCommand(r => r.GetSortedSetCount(SortedSetKey), intResult => collectionCounts.Add(intResult));
- pipeline.QueueCommand(r => r.IncrementValue(Key), intResult => incrementResults.Add(intResult));
-
- pipeline.Flush();
- }
-
- Assert.That(containsItem, Is.True);
- Assert.That(Redis.GetValue(Key), Is.EqualTo("2"));
- Assert.That(incrementResults, Is.EquivalentTo(new List<long> { 1, 2 }));
- Assert.That(collectionCounts, Is.EquivalentTo(new List<int> { 2, 1, 3 }));
- Assert.That(Redis.GetAllItemsFromList(ListKey), Is.EquivalentTo(new List<string> { "listitem1", "listitem2" }));
- Assert.That(Redis.GetAllItemsFromSet(SetKey), Is.EquivalentTo(new List<string> { "setitem" }));
- Assert.That(Redis.GetAllItemsFromSortedSet(SortedSetKey), Is.EquivalentTo(new List<string> { "sortedsetitem1", "sortedsetitem2", "sortedsetitem3" }));
- }
-
- [Test]
- public void Can_call_multi_string_operations_in_pipeline()
- {
- string item1 = null;
- string item4 = null;
-
- var results = new List<string>();
- Assert.That(Redis.GetListCount(ListKey), Is.EqualTo(0));
- using (var pipeline = Redis.CreatePipeline())
- {
- pipeline.QueueCommand(r => r.AddItemToList(ListKey, "listitem1"));
- pipeline.QueueCommand(r => r.AddItemToList(ListKey, "listitem2"));
- pipeline.QueueCommand(r => r.AddItemToList(ListKey, "listitem3"));
- pipeline.QueueCommand(r => r.GetAllItemsFromList(ListKey), x => results = x);
- pipeline.QueueCommand(r => r.GetItemFromList(ListKey, 0), x => item1 = x);
- pipeline.QueueCommand(r => r.GetItemFromList(ListKey, 4), x => item4 = x);
-
- pipeline.Flush();
- }
-
- Assert.That(Redis.GetListCount(ListKey), Is.EqualTo(3));
- Assert.That(results, Is.EquivalentTo(new List<string> { "listitem1", "listitem2", "listitem3" }));
- Assert.That(item1, Is.EqualTo("listitem1"));
- Assert.That(item4, Is.Null);
- }
+ [Test]
+ public void Can_call_single_operation_with_callback_3_Times_in_pipeline()
+ {
+ var results = new List<long>();
+ Assert.That(Redis.GetValue(Key), Is.Null);
+ using (var pipeline = Redis.CreatePipeline())
+ {
+ pipeline.QueueCommand(r => r.IncrementValue(Key), results.Add);
+ pipeline.QueueCommand(r => r.IncrementValue(Key), results.Add);
+ pipeline.QueueCommand(r => r.IncrementValue(Key), results.Add);
+
+ pipeline.Flush();
+ }
+
+ Assert.That(Redis.GetValue(Key), Is.EqualTo("3"));
+ Assert.That(results, Is.EquivalentTo(new List<long> { 1, 2, 3 }));
+ }
+
+ [Test]
+ public void Supports_different_operation_types_in_same_pipeline()
+ {
+ var incrementResults = new List<long>();
+ var collectionCounts = new List<long>();
+ var containsItem = false;
+
+ Assert.That(Redis.GetValue(Key), Is.Null);
+ using (var pipeline = Redis.CreatePipeline())
+ {
+ pipeline.QueueCommand(r => r.IncrementValue(Key), intResult => incrementResults.Add(intResult));
+ pipeline.QueueCommand(r => r.AddItemToList(ListKey, "listitem1"));
+ pipeline.QueueCommand(r => r.AddItemToList(ListKey, "listitem2"));
+ pipeline.QueueCommand(r => r.AddItemToSet(SetKey, "setitem"));
+ pipeline.QueueCommand(r => r.SetContainsItem(SetKey, "setitem"), b => containsItem = b);
+ pipeline.QueueCommand(r => r.AddItemToSortedSet(SortedSetKey, "sortedsetitem1"));
+ pipeline.QueueCommand(r => r.AddItemToSortedSet(SortedSetKey, "sortedsetitem2"));
+ pipeline.QueueCommand(r => r.AddItemToSortedSet(SortedSetKey, "sortedsetitem3"));
+ pipeline.QueueCommand(r => r.GetListCount(ListKey), intResult => collectionCounts.Add(intResult));
+ pipeline.QueueCommand(r => r.GetSetCount(SetKey), intResult => collectionCounts.Add(intResult));
+ pipeline.QueueCommand(r => r.GetSortedSetCount(SortedSetKey), intResult => collectionCounts.Add(intResult));
+ pipeline.QueueCommand(r => r.IncrementValue(Key), intResult => incrementResults.Add(intResult));
+
+ pipeline.Flush();
+ }
+
+ Assert.That(containsItem, Is.True);
+ Assert.That(Redis.GetValue(Key), Is.EqualTo("2"));
+ Assert.That(incrementResults, Is.EquivalentTo(new List<long> { 1, 2 }));
+ Assert.That(collectionCounts, Is.EquivalentTo(new List<int> { 2, 1, 3 }));
+ Assert.That(Redis.GetAllItemsFromList(ListKey), Is.EquivalentTo(new List<string> { "listitem1", "listitem2" }));
+ Assert.That(Redis.GetAllItemsFromSet(SetKey), Is.EquivalentTo(new List<string> { "setitem" }));
+ Assert.That(Redis.GetAllItemsFromSortedSet(SortedSetKey), Is.EquivalentTo(new List<string> { "sortedsetitem1", "sortedsetitem2", "sortedsetitem3" }));
+ }
+
+ [Test]
+ public void Can_call_multi_string_operations_in_pipeline()
+ {
+ string item1 = null;
+ string item4 = null;
+
+ var results = new List<string>();
+ Assert.That(Redis.GetListCount(ListKey), Is.EqualTo(0));
+ using (var pipeline = Redis.CreatePipeline())
+ {
+ pipeline.QueueCommand(r => r.AddItemToList(ListKey, "listitem1"));
+ pipeline.QueueCommand(r => r.AddItemToList(ListKey, "listitem2"));
+ pipeline.QueueCommand(r => r.AddItemToList(ListKey, "listitem3"));
+ pipeline.QueueCommand(r => r.GetAllItemsFromList(ListKey), x => results = x);
+ pipeline.QueueCommand(r => r.GetItemFromList(ListKey, 0), x => item1 = x);
+ pipeline.QueueCommand(r => r.GetItemFromList(ListKey, 4), x => item4 = x);
+
+ pipeline.Flush();
+ }
+
+ Assert.That(Redis.GetListCount(ListKey), Is.EqualTo(3));
+ Assert.That(results, Is.EquivalentTo(new List<string> { "listitem1", "listitem2", "listitem3" }));
+ Assert.That(item1, Is.EqualTo("listitem1"));
+ Assert.That(item4, Is.Null);
+ }
[Test]
// Operations that are not supported in older versions will look at server info to determine what to do.
// If server info is fetched each time, then it will interfer with pipeline
@@ -228,7 +228,7 @@ public void Can_call_operation_not_supported_on_older_servers_in_pipeline()
var temp = new byte[1];
using (var pipeline = Redis.CreatePipeline())
{
- pipeline.QueueCommand(r => ((RedisNativeClient)r).SetEx(Key + "key",5,temp));
+ pipeline.QueueCommand(r => ((RedisNativeClient)r).SetEx(Key + "key", 5, temp));
pipeline.Flush();
}
}
@@ -276,18 +276,18 @@ public void Pipeline_can_be_contain_watch()
}
}
- [Test]
+ [Test]
public void Can_call_AddRangeToSet_in_pipeline()
- {
- using (var pipeline = Redis.CreatePipeline())
- {
- var key = "pipeline-test";
+ {
+ using (var pipeline = Redis.CreatePipeline())
+ {
+ var key = "pipeline-test";
pipeline.QueueCommand(r => r.Remove(key));
- pipeline.QueueCommand(r => r.AddRangeToSet(key, new[]{ "A", "B", "C" }.ToList()));
+ pipeline.QueueCommand(r => r.AddRangeToSet(key, new[] { "A", "B", "C" }.ToList()));
pipeline.Flush();
- }
- }
- }
+ }
+ }
+ }
}
View
99 tests/ServiceStack.Redis.Tests/RedisSentinelTests.cs
@@ -10,63 +10,63 @@
namespace ServiceStack.Redis.Tests
{
[Ignore("Reenable when CI has Sentinel")]
- [TestFixture, Category("Integration")]
- public class RedisSentinelTests
- : RedisClientTestsBase
- {
- protected RedisClient RedisSentinel;
+ [TestFixture, Category("Integration")]
+ public class RedisSentinelTests
+ : RedisClientTestsBase
+ {
+ protected RedisClient RedisSentinel;
- public override void OnBeforeEachTest()
- {
- base.OnBeforeEachTest();
+ public override void OnBeforeEachTest()
+ {
+ base.OnBeforeEachTest();
RedisSentinel = new RedisClient(TestConfig.SentinelHost, TestConfig.RedisSentinelPort);
- }
+ }
- public override void TearDown()
- {
- base.TearDown();
+ public override void TearDown()
+ {
+ base.TearDown();
- RedisSentinel.Dispose();
- }
+ RedisSentinel.Dispose();
+ }
- [Test]
- public void Can_Ping_Sentinel()
- {
- Assert.True(RedisSentinel.Ping());
- }
+ [Test]
+ public void Can_Ping_Sentinel()
+ {
+ Assert.True(RedisSentinel.Ping());
+ }
- [Test]
- public void Can_Get_Sentinel_Masters()
- {
- object[] masters = RedisSentinel.Sentinel("masters");
+ [Test]
+ public void Can_Get_Sentinel_Masters()
+ {
+ object[] masters = RedisSentinel.Sentinel("masters");
- Assert.AreEqual(masters.Count(), TestConfig.MasterHosts.Count());
- }
+ Assert.AreEqual(masters.Count(), TestConfig.MasterHosts.Count());
+ }
- [Test]
- public void Can_Get_Sentinel_Slaves()
- {
- object[] slaves = RedisSentinel.Sentinel("slaves", TestConfig.MasterName);
+ [Test]
+ public void Can_Get_Sentinel_Slaves()
+ {
+ object[] slaves = RedisSentinel.Sentinel("slaves", TestConfig.MasterName);
Assert.That(slaves.Count(), Is.GreaterThan(0));
- }
+ }
- [Test]
- public void Can_Get_Master_Addr()
- {
- object[] addr = RedisSentinel.Sentinel("get-master-addr-by-name", TestConfig.MasterName);
+ [Test]
+ public void Can_Get_Master_Addr()
+ {
+ object[] addr = RedisSentinel.Sentinel("get-master-addr-by-name", TestConfig.MasterName);
- string host = Encoding.UTF8.GetString((byte[])addr[0]);
- string port = Encoding.UTF8.GetString((byte[])addr[1]);
+ string host = Encoding.UTF8.GetString((byte[])addr[0]);
+ string port = Encoding.UTF8.GetString((byte[])addr[1]);
// IP of localhost
Assert.That(host, Is.EqualTo("127.0.0.1").Or.EqualTo(TestConfig.SentinelHost));
- Assert.AreEqual(port, TestConfig.RedisPort.ToString());
- }
+ Assert.AreEqual(port, TestConfig.RedisPort.ToString());
+ }
[Test]
public void Can_Get_Redis_ClientsManager()
@@ -88,8 +88,10 @@ public void Can_specify_Timeout_on_RedisManager()
{
var sentinel = new RedisSentinel(new[] { "{0}:{1}".Fmt(TestConfig.SentinelHost, TestConfig.RedisSentinelPort) }, TestConfig.MasterName)
{
- RedisManagerFactory = {
- OnInit = r => {
+ RedisManagerFactory =
+ {
+ OnInit = r =>
+ {
((PooledRedisClientManager)r).IdleTimeOutSecs = 20;
}
}
@@ -106,8 +108,9 @@ public void Can_specify_Timeout_on_RedisManager()
[Test]
public void Can_specify_db_on_RedisSentinel()
{
- var sentinelHosts = new[] {"{0}:{1}".Fmt(TestConfig.SentinelHost, TestConfig.RedisSentinelPort)};
- var sentinel = new RedisSentinel(sentinelHosts, TestConfig.MasterName) {
+ var sentinelHosts = new[] { "{0}:{1}".Fmt(TestConfig.SentinelHost, TestConfig.RedisSentinelPort) };
+ var sentinel = new RedisSentinel(sentinelHosts, TestConfig.MasterName)
+ {
HostFilter = host => "{0}?db=1".Fmt(host)
};
@@ -121,12 +124,12 @@ public void Can_specify_db_on_RedisSentinel()
[Test]
public void Run_sentinel_for_10_minutes()
{
- LogManager.LogFactory = new ConsoleLogFactory(debugEnabled:true);
+ LogManager.LogFactory = new ConsoleLogFactory(debugEnabled: true);
var sentinelHost = "{0}:{1}".Fmt(TestConfig.SentinelHost, TestConfig.RedisSentinelPort);
var sentinel = new RedisSentinel(sentinelHost, TestConfig.MasterName)
{
- OnFailover = manager =>
+ OnFailover = manager =>
{
"Redis Managers Failed Over to new hosts".Print();
},
@@ -137,17 +140,17 @@ public void Run_sentinel_for_10_minutes()
OnSentinelMessageReceived = (channel, msg) =>
{
"Received '{0}' on channel '{1}' from Sentinel".Print(channel, msg);
- },
+ },
};
var redisManager = sentinel.Start();
var aTimer = new Timer
{
- Interval = 1000,
+ Interval = 1000,
Enabled = true
};
- aTimer.Elapsed += (sender, args) =>
+ aTimer.Elapsed += (sender, args) =>
{
"Incrementing key".Print();
@@ -170,5 +173,5 @@ public void Run_sentinel_for_10_minutes()
Thread.Sleep(TimeSpan.FromMinutes(10));
}
- }
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.