public void DeletingGame_ShouldRemoveOneRecordInPrimaryAndCache() { // Arrange var sqlConnectionString = ConfigurationManager.ConnectionStrings["test"].ToString(); var redisConnectionString = ConfigurationManager.ConnectionStrings["redis-test"].ToString(); var sqlAdapter = new SqlServerAdapter(sqlConnectionString); var redisAdapter = new RedisAdapter(ConnectionMultiplexer.Connect(redisConnectionString)); var cachedAdapter = new SqlServerCachedAdapter(sqlAdapter, redisAdapter); // create new game and insert it, so we have something to delete var gameToUpdate = new TicTacToeData(); cachedAdapter.Save(gameToUpdate); int numPreExistingGamesSql = AdapterTestHelpers.CountSqlGames(sqlConnectionString); int numPreExistingGamesRedis = AdapterTestHelpers.CountRedisGames(redisConnectionString); // Act cachedAdapter.Delete(gameToUpdate.Id); // Assert int numPostExistingGamesSql = AdapterTestHelpers.CountSqlGames(sqlConnectionString); int numPostExistingGamesRedis = AdapterTestHelpers.CountRedisGames(redisConnectionString); Assert.AreEqual(numPreExistingGamesSql - 1, numPostExistingGamesSql); Assert.AreEqual(numPreExistingGamesRedis - 1, numPostExistingGamesRedis); }
public void ReadingAllGames_ShouldReturnAllGames() { // Arrange var sqlConnectionString = ConfigurationManager.ConnectionStrings["test"].ToString(); var redisConnectionString = ConfigurationManager.ConnectionStrings["redis-test"].ToString(); var sqlAdapter = new SqlServerAdapter(sqlConnectionString); var redisAdapter = new RedisAdapter(ConnectionMultiplexer.Connect(redisConnectionString)); var cachedAdapter = new SqlServerCachedAdapter(sqlAdapter, redisAdapter); var insertedGames = new List <TicTacToeData>() { new TicTacToeData(), new TicTacToeData() }; foreach (var game in insertedGames) { cachedAdapter.Save(game); } // Act var allGames = cachedAdapter.ReadAll(); // Assert foreach (var game in insertedGames) { Assert.IsTrue(allGames.Contains(game)); } }
public void SavingExistingObject_ShouldPreserveNumberOfRecordsInPrimaryAndCache() { // Arrange var sqlConnectionString = ConfigurationManager.ConnectionStrings["test"].ToString(); var redisConnectionString = ConfigurationManager.ConnectionStrings["redis-test"].ToString(); var sqlAdapter = new SqlServerAdapter(sqlConnectionString); var redisAdapter = new RedisAdapter(ConnectionMultiplexer.Connect(redisConnectionString)); var cachedAdapter = new SqlServerCachedAdapter(sqlAdapter, redisAdapter); // create new game and insert it, so we have something to update var gameToUpdate = new TicTacToeData(); cachedAdapter.Save(gameToUpdate); int numPreExistingGamesSql = AdapterTestHelpers.CountSqlGames(sqlConnectionString); int numPreExistingGamesRedis = AdapterTestHelpers.CountRedisGames(redisConnectionString); // Act gameToUpdate.CurrentPlayer = Player.O; cachedAdapter.Save(gameToUpdate); // Assert int numPostExistingGamesSql = AdapterTestHelpers.CountSqlGames(sqlConnectionString); int numPostExistingGamesRedis = AdapterTestHelpers.CountRedisGames(redisConnectionString); Assert.AreEqual(numPreExistingGamesSql, numPostExistingGamesSql); Assert.AreEqual(numPreExistingGamesRedis, numPostExistingGamesRedis); }
private void BuildRedisCache() { redisAdapter = new RedisAdapter(RedisHost, RedisPort, RedisPassword, RedisDatabase, RedisConnectTimeout, RedisConnectRetry, RedisSyncTimeout); splitCache = new RedisSplitCache(redisAdapter, RedisUserPrefix); segmentCache = new RedisSegmentCache(redisAdapter, RedisUserPrefix); metricsCache = new RedisMetricsCache(redisAdapter, SdkMachineIP, SdkVersion, RedisUserPrefix); impressionsCache = new RedisImpressionsCache(redisAdapter, SdkMachineIP, SdkVersion, RedisUserPrefix); }
public new void SetUp() { var endpoint = Redis.GetEndPoints().First(); var server = Redis.GetServer(endpoint); server.FlushDatabase(); Database = Redis.GetDatabase(); Adapter = new RedisAdapter(Database); }
public void ExecuteDelShouldReturnFalseOnException() { //Arrange var adapter = new RedisAdapter("", "", ""); //Act var isDel = adapter.Del("testdel.test_key"); //Assert Assert.IsFalse(isDel); }
public void ExecuteKeysShouldReturnEmptyArrayOnException() { //Arrange var adapter = new RedisAdapter("", "", ""); //Act var result = adapter.Keys("test.*"); //Assert Assert.AreEqual(0, result.Count()); }
public void ExecuteSMembersShouldReturnFalseOnException() { //Arrange var adapter = new RedisAdapter("", "", ""); //Act var result = adapter.SMembers("test_key_set"); //Assert Assert.AreEqual(0, result.Count()); }
public void ExecuteSAddShouldReturnZeroOnException() { //Arrange var adapter = new RedisAdapter("", "", ""); //Act var setCount = adapter.SAdd("test_key_set_multiple", new RedisValue[] { "test_value", "test_value2" }); //Assert Assert.AreEqual(0, setCount); }
public void ExecuteSRemShouldReturnZeroOnException() { //Arrange var adapter = new RedisAdapter("", "", ""); //Act var remCount = adapter.SRem("test_key_set", new RedisValue[] { "test_value2" }); //Assert Assert.AreEqual(0, remCount); }
public void ExecuteIncrShouldReturnZeroOnException() { //Arrange var adapter = new RedisAdapter("", "", ""); //Act var result = adapter.IcrBy("test_count", 2); //Assert Assert.AreEqual(0, result); }
public void ExecuteSetShouldReturnFalseOnException() { //Arrange var adapter = new RedisAdapter("", "", ""); //Act var isSet = adapter.Set("test_key", "test_value"); //Assert Assert.IsFalse(isSet); }
public void ExecuteGetShouldReturnEmptyOnException() { //Arrange var adapter = new RedisAdapter("", "", ""); //Act var result = adapter.Get("test_key"); //Assert Assert.AreEqual(String.Empty, result); }
public void ExecuteGetShouldReturnEmptyArrayOnException() { //Arrange var adapter = new RedisAdapter("", "", ""); //Act var result = adapter.Get(new RedisKey[] { "test_key", "test_key2", "test_key3" }); //Assert Assert.AreEqual(0, result.Count()); }
public void ExecuteSAddShouldReturnFalseOnException() { //Arrange var adapter = new RedisAdapter("", "", ""); //Act var setCount = adapter.SAdd("test_key_set", "test_value_1"); //Assert Assert.IsFalse(setCount); }
public RedisController() { try { ra = RedisAdapter.Create(this.GetType().Name); } catch (Exception ex) { lasterror = ex; WebLog.LogException(ex); } }
public void SetUp() { var endpoint = Redis.GetEndPoints().First(); var server = Redis.GetServer(endpoint); server.FlushDatabase(); var database = Redis.GetDatabase(); adapter = new RedisAdapter(database); flipper = new Flipper(adapter); rubyAdapter = new RedisRubyAdapter(); }
public void GetConfigWithoutTls() { //Arrange var adapter = new RedisAdapter("localhost", "6379", "", 0, 1000, 5, 1000); //Act var result = adapter.GetConfig(); //Assert Assert.AreEqual(1, result.EndPoints.Count); Assert.AreEqual(string.Empty, result.Password); Assert.AreEqual(1000, result.ConnectTimeout); Assert.AreEqual(1000, result.SyncTimeout); Assert.IsFalse(result.Ssl); }
private void BuildRedisCache() { redisAdapter = new RedisAdapter(RedisHost, RedisPort, RedisPassword, RedisDatabase, RedisConnectTimeout, RedisConnectRetry, RedisSyncTimeout); if (BlockMilisecondsUntilReady > 0 && !redisAdapter.IsConnected()) { throw new TimeoutException($"SDK was not ready in {BlockMilisecondsUntilReady} miliseconds. Could not connect to Redis"); } splitCache = new RedisSplitCache(redisAdapter, RedisUserPrefix); segmentCache = new RedisSegmentCache(redisAdapter, RedisUserPrefix); metricsCache = new RedisMetricsCache(redisAdapter, SdkMachineIP, SdkVersion, RedisUserPrefix); impressionsCacheRedis = new RedisImpressionsCache(redisAdapter, SdkMachineIP, SdkVersion, RedisUserPrefix); eventsCache = new RedisEventsCache(redisAdapter, SdkMachineName, SdkMachineIP, SdkVersion, RedisUserPrefix); _trafficTypeValidator = new TrafficTypeValidator(_log, splitCache); }
private IContainer BuildContainer() { var builder = new ContainerBuilder(); // controllers builder.RegisterType <GameController>().InstancePerRequest(); builder.RegisterType <DataManager>().As <IDataManager>().InstancePerLifetimeScope(); builder.RegisterType <GameManagerFactory>().As <IGameManagerFactory>().InstancePerLifetimeScope(); bool isUsingCache; var isUsingCacheSetting = ConfigurationManager.AppSettings["useCache"]; if (bool.TryParse(isUsingCacheSetting, out isUsingCache) && isUsingCache) { // data adapters builder.Register(x => { var redisConnectionString = ConfigurationManager.ConnectionStrings["redis-azure"].ToString(); return(ConnectionMultiplexer.Connect(redisConnectionString)); }).As <ConnectionMultiplexer>().SingleInstance(); builder.Register(x => { var sqlConnectionString = ConfigurationManager.ConnectionStrings["sql-azure"].ToString(); var sqlAdapter = new SqlServerAdapter(sqlConnectionString); var connectionMultiplexer = x.Resolve <ConnectionMultiplexer>(); var redisAdapter = new RedisAdapter(connectionMultiplexer); return(new SqlServerCachedAdapter(sqlAdapter, redisAdapter)); }).As <IGenericDataAdapter <ITicTacToeData> >().InstancePerLifetimeScope(); } else { builder.Register(x => { var sqlConnectionString = ConfigurationManager.ConnectionStrings["sql-azure"].ToString(); return(new SqlServerAdapter(sqlConnectionString)); }).As <IGenericDataAdapter <ITicTacToeData> >().InstancePerLifetimeScope(); } return(builder.Build()); }
public void SaveThenRead_ShouldRoundTrip() { // Arrange var sqlConnectionString = ConfigurationManager.ConnectionStrings["test"].ToString(); var redisConnectionString = ConfigurationManager.ConnectionStrings["redis-test"].ToString(); var sqlAdapter = new SqlServerAdapter(sqlConnectionString); var redisAdapter = new RedisAdapter(ConnectionMultiplexer.Connect(redisConnectionString)); var cachedAdapter = new SqlServerCachedAdapter(sqlAdapter, redisAdapter); var gameData = new TicTacToeData(); // change gameData to make sure Read() isn't just constructing new TicTacToeData() gameData.CurrentPlayer = Player.O; // Act cachedAdapter.Save(gameData); var(readSuccessfully, readData) = cachedAdapter.Read(gameData.Id); // Assert Assert.IsTrue(readSuccessfully); Assert.AreEqual(gameData, readData); }
public void SavingNewObject_ShouldInsertOneRecordInPrimaryAndCache() { // Arrange var sqlConnectionString = ConfigurationManager.ConnectionStrings["test"].ToString(); var redisConnectionString = ConfigurationManager.ConnectionStrings["redis-test"].ToString(); var sqlAdapter = new SqlServerAdapter(sqlConnectionString); var redisAdapter = new RedisAdapter(ConnectionMultiplexer.Connect(redisConnectionString)); var cachedAdapter = new SqlServerCachedAdapter(sqlAdapter, redisAdapter); var newGame = new TicTacToeData(); int numPreExistingGamesSql = AdapterTestHelpers.CountSqlGames(sqlConnectionString); int numPreExistingGamesRedis = AdapterTestHelpers.CountRedisGames(redisConnectionString); // Act cachedAdapter.Save(newGame); // Assert int numPostExistingGamesSql = AdapterTestHelpers.CountSqlGames(sqlConnectionString); int numPostExistingGamesRedis = AdapterTestHelpers.CountRedisGames(redisConnectionString); Assert.AreEqual(numPreExistingGamesSql + 1, numPostExistingGamesSql); Assert.AreEqual(numPreExistingGamesRedis + 1, numPostExistingGamesRedis); }
static void Main(string[] args) { //Redis part string redisConnectionString = "localhost"; //define redis connection string clients.Add(new RemoteHubOverRedis <string>(Guid.NewGuid(), redisConnectionString, Received)); //create one client to redis and add it to the clients list clients.Add(new RemoteHubOverRedis <string>(Guid.NewGuid(), redisConnectionString, Received)); //create one more client to redis and add it to the clients list clientNames.Add(clients[0].ClientId, "Client 0"); //name the 1st client as Client 0 clientNames.Add(clients[1].ClientId, "Client 1"); //name the 2nd client as Client 1 clients[0].Start(); //start the 1st client clients[1].Start(); //start the 2nd client RedisAdapter <byte[]> redisAdapterOnRedisHub = new RedisAdapter <byte[]>(redisConnectionString); //create an adapter connected to redis for later using in Switch 2 //Switch1 part TcpListener[] tcpListeners = new TcpListener[] //open 3 tcp listeners { new TcpListener(IPAddress.Loopback, 60002), new TcpListener(IPAddress.Loopback, 60003), new TcpListener(IPAddress.Loopback, 60004) }; foreach (var tcpListener in tcpListeners) //start tcp listeners { tcpListener.Start(); } Task <TcpClient>[] acceptingTasks = Array.ConvertAll(tcpListeners, i => i.AcceptTcpClientAsync()); //waiting for connection for each server TcpClient[] tcpClients = new TcpClient[] //prepare 6 tcp links, connection relation: 0<->3, 1<->4, 2<->5 { new TcpClient("localhost", 60002), new TcpClient("localhost", 60003), new TcpClient("localhost", 60004), acceptingTasks[0].Result, acceptingTasks[1].Result, acceptingTasks[2].Result }; foreach (var tcpListener in tcpListeners) //stop all listeners { tcpListener.Stop(); } NetworkStream[] streamsOfTcpClients = Array.ConvertAll(tcpClients, i => i.GetStream()); //get network streams from tcp links. StreamAdapter <byte[]>[] streamAdaptersOnSwitch1 = new StreamAdapter <byte[]>[] //create adapters from first 3 tcp links. { new StreamAdapter <byte[]>(streamsOfTcpClients[0], streamsOfTcpClients[0]), new StreamAdapter <byte[]>(streamsOfTcpClients[1], streamsOfTcpClients[1]), new StreamAdapter <byte[]>(streamsOfTcpClients[2], streamsOfTcpClients[2]) }; adapterNamesForSwitch1[streamAdaptersOnSwitch1[0]] = "To Client 2"; //name the 1st adapter as To Client 2 adapterNamesForSwitch1[streamAdaptersOnSwitch1[1]] = "To Client 3"; //name the 2nd adapter as To Client 3 adapterNamesForSwitch1[streamAdaptersOnSwitch1[2]] = "To Switch 2"; //name the 3rd adapter as To Switch 2 for later using in Switch 2 clients.Add(new RemoteHubOverStream <string>(Guid.NewGuid(), streamsOfTcpClients[3], streamsOfTcpClients[3], Received)); //create one client based on the 3rd stream which is connected to the 1st stream adapter. clients.Add(new RemoteHubOverStream <string>(Guid.NewGuid(), streamsOfTcpClients[4], streamsOfTcpClients[4], Received)); //create one more client based on the 4th stream which is connected to the 2nd stream adapter. clientNames.Add(clients[2].ClientId, "Client 2"); //name the new created client as Client 2 clientNames.Add(clients[3].ClientId, "Client 3"); //name the 2nd new created client as Client 3 clients[2].Start(); //start the new created client clients[3].Start(); //start the 2nd new created client StreamAdapter <byte[]> streamAdapterOnSwitch2 = new StreamAdapter <byte[]>(streamsOfTcpClients[5], streamsOfTcpClients[5]); //create one adapter based on the 5th stream which is connected to the 3rd stream adapter. RemoteHubSwitch remoteHubSwitch1 = new RemoteHubSwitch(); //create the 1st Switch remoteHubSwitch1.RemoteClientAdded += RemoteHubSwitch1_RemoteClientAdded; remoteHubSwitch1.RemoteClientChanged += RemoteHubSwitch1_RemoteClientChanged; remoteHubSwitch1.RemoteClientRemoved += RemoteHubSwitch1_RemoteClientRemoved; //remoteHubSwitch1.MessageRouted += RemoteHubSwitch1_MessageRouted; //remoteHubSwitch1.MessageRoutingFailed += RemoteHubSwitch1_MessageRoutingFailed; remoteHubSwitch1.AddAdapters(streamAdaptersOnSwitch1); //add the new created adapter to the 1st Switch //Switch2 part adapterNamesForSwitch2[redisAdapterOnRedisHub] = "To Redis"; //name the redis adapter for switch 2 as To Redis adapterNamesForSwitch2[streamAdapterOnSwitch2] = "To Switch 1"; //name the stream adapter for switch 2 as To Switch 1 RemoteHubSwitch remoteHubSwitch2 = new RemoteHubSwitch(); //create the 2nd Switch remoteHubSwitch2.RemoteClientAdded += RemoteHubSwitch2_RemoteClientAdded; remoteHubSwitch2.RemoteClientChanged += RemoteHubSwitch2_RemoteClientChanged; remoteHubSwitch2.RemoteClientRemoved += RemoteHubSwitch2_RemoteClientRemoved; //remoteHubSwitch2.MessageRouted += RemoteHubSwitch2_MessageRouted; //remoteHubSwitch2.MessageRoutingFailed += RemoteHubSwitch2_MessageRoutingFailed; remoteHubSwitch2.AddAdapter(redisAdapterOnRedisHub); //add the redis adapter to Switch 2 remoteHubSwitch2.AddAdapter(streamAdapterOnSwitch2); //add the switch adapter to Switch 2 //Test SimpleMessageTest(); //AddRemoveClientTest(remoteHubSwitch2); //ConnectAndDisconnectSwitchTest(remoteHubSwitch1, streamAdaptersOnSwitch1[2]); //VirtualHostTest(remoteHubSwitch1, streamAdaptersOnSwitch1[2], clients[2]); Console.WriteLine("Press any key to quit..."); Console.ReadKey(true); //Dispose foreach (var client in clients) //stop all clients { client.Stop(); ((IDisposable)client).Dispose(); } remoteHubSwitch1.RemoveAllAdapters(true); //remove all adapters attached in Switch 1 remoteHubSwitch2.RemoveAllAdapters(true); //remove all adapters attached in Switch 2 redisAdapterOnRedisHub.Dispose(); streamAdapterOnSwitch2.Dispose(); foreach (var adapter in streamAdaptersOnSwitch1) { adapter.Dispose(); } foreach (var stream in streamsOfTcpClients) { stream.Close(); stream.Dispose(); } foreach (var tcpClient in tcpClients) { tcpClient.Close(); tcpClient.Dispose(); } }
public void Setup() { ConnectionString = ConfigurationManager.ConnectionStrings["redis-test"].ToString(); Adapter = new RedisAdapter(ConnectionMultiplexer.Connect(ConnectionString)); }