static void Main(string[] args) { var coll = new StateCollection(); var state = new SomeState(); coll.AddState(state); Console.ReadKey(); }
public void Foo(SomeState newState) { lock (this) { if (someState == null) { someState = newState; } } Interlocked.CompareExchange <SomeState>(ref someState, newState, null); }
public async Task TestConnectionLocalRedis() { var logger = new Mock <Logger>(); var runtime = new Mock <IProviderRuntime>(); runtime.Setup(r => r.GetLogger(It.IsAny <string>())) .Returns(logger.Object); var serviceProvider = new Mock <IServiceProvider>(); runtime.SetupGet(r => r.ServiceProvider) .Returns(serviceProvider.Object); var config = new Mock <IProviderConfiguration>(); config.SetupGet(c => c.Properties).Returns(default(ReadOnlyDictionary <string, string>)); var provider = new RedisStorageProvider(); var cfg = new Dictionary <string, string>(); cfg["DataConnectionString"] = "127.0.0.1"; cfg["Serializer"] = RedisStorageProvider.Serializers.Protobuf; config.SetupGet(c => c.Properties).Returns(new ReadOnlyDictionary <string, string>(cfg)); await provider.Init("store2", runtime.Object, config.Object); var defaultStateObj = new SomeState(); var stateMock = new Mock <IGrainState>(); var stateObj = new SomeState(); Assert.True(stateObj.Equals(defaultStateObj)); Assert.Equal(stateObj.GetHashCode(), defaultStateObj.GetHashCode()); var state = stateMock.Object; stateMock.SetupGet(s => s.State) .Returns(stateObj); await provider.ReadStateAsync("proto123123123", null, state); stateMock.VerifySet(s => s.State = It.IsAny <object>(), Times.Never()); await provider.WriteStateAsync("proto", null, state); stateMock.VerifyGet(s => s.State, Times.Once()); await provider.ReadStateAsync("proto", null, state); stateMock.VerifySet(s => s.State = It.Is <SomeState>(o => o.Equals(stateObj)), Times.Once()); }
public ProtoVsJson() { var logger = new Mock <Logger>(); var runtime = new Mock <IProviderRuntime>(); runtime.Setup(r => r.GetLogger(It.IsAny <string>())) .Returns(logger.Object); var serviceProvider = new Mock <IServiceProvider>(); runtime.SetupGet(r => r.ServiceProvider) .Returns(serviceProvider.Object); var yugaByteRedisConnCfg = new ConfigurationOptions { EndPoints = { { "127.0.0.1", 6379 }, }, CommandMap = CommandMap.Create(new HashSet <string> { // EXCLUDE commands not supported by YugaByte "SUBSCRIBE", "CLUSTER", "PING", "TIME" }, available: false) }; var rawRedisConnCfg = new ConfigurationOptions { EndPoints = { { "127.0.0.1", 6380 }, }, CommandMap = CommandMap.Create(new HashSet <string> { // EXCLUDE commands not supported by YugaByte "SUBSCRIBE", "CLUSTER", "PING", "TIME" }, available: false) }; var yugaByteConnection = ConnectionMultiplexer.Connect(yugaByteRedisConnCfg); var redisConnection = ConnectionMultiplexer.Connect(rawRedisConnCfg); var database = yugaByteConnection.GetDatabase(); database.Execute("FLUSHALL").IsNull.Should().BeFalse(); database = redisConnection.GetDatabase(); database.Execute("FLUSHALL").IsNull.Should().BeFalse(); var config = new Mock <IProviderConfiguration>(); var cfg = new Dictionary <string, string>(); cfg["DataConnectionString"] = "127.0.0.1:6379"; cfg["Serializer"] = RedisStorageProvider.Serializers.Json; config.SetupGet(c => c.Properties).Returns(new ReadOnlyDictionary <string, string>(cfg)); serviceProvider .Setup(c => c.GetService(It.Is <Type>(t => t == typeof(IConnectionMultiplexer)))) .Returns(yugaByteConnection) .Verifiable(); _yugaByte_jsonProvider = new RedisStorageProvider(); _yugaByte_jsonProvider.Init("json", runtime.Object, config.Object).Wait(); serviceProvider.Verify(); cfg = new Dictionary <string, string>(); cfg["DataConnectionString"] = "127.0.0.1:6379"; cfg["Serializer"] = RedisStorageProvider.Serializers.Protobuf; config.SetupGet(c => c.Properties).Returns(new ReadOnlyDictionary <string, string>(cfg)); _yugaByte_protoProvider = new RedisStorageProvider(); _yugaByte_protoProvider.Init("proto", runtime.Object, config.Object).Wait(); serviceProvider.Verify(); cfg = new Dictionary <string, string>(); cfg["DataConnectionString"] = "127.0.0.1:6380"; cfg["Serializer"] = RedisStorageProvider.Serializers.Json; config.SetupGet(c => c.Properties).Returns(new ReadOnlyDictionary <string, string>(cfg)); serviceProvider .Setup(c => c.GetService(It.Is <Type>(t => t == typeof(IConnectionMultiplexer)))) .Returns(redisConnection) .Verifiable(); _redis_jsonProvider = new RedisStorageProvider(); _redis_jsonProvider.Init("json", runtime.Object, config.Object).Wait(); serviceProvider.Verify(); cfg = new Dictionary <string, string>(); cfg["DataConnectionString"] = "127.0.0.1:6380"; cfg["Serializer"] = RedisStorageProvider.Serializers.Protobuf; config.SetupGet(c => c.Properties).Returns(new ReadOnlyDictionary <string, string>(cfg)); _redis_protoProvider = new RedisStorageProvider(); _redis_protoProvider.Init("proto", runtime.Object, config.Object).Wait(); serviceProvider.Verify(); var stateMock = new Mock <IGrainState>(); var state = new SomeState(); stateMock.SetupGet(s => s.State) .Returns(state); _state = stateMock.Object; }
private bool Equals(SomeState other) => ReferenceEquals(this, other) || value.Equals(other.value);
public void Restore_State(SomeState f_State) { ((ISomeState)f_State).Restore_State(this); }