public void TestDBStorageSet() { _testStorage.Set("test1", "Value11"); string val = _testStorage.Get("test1"); Assert.IsTrue(val == "Value11"); }
private string LookUpChainNameByAddress(Address address) { var key = ChainAddressMapKey + address.Text; if (_vars.ContainsKey(key)) { var bytes = _vars.Get(key); return(Encoding.UTF8.GetString(bytes)); } return(null); }
/// <summary> /// Sets the app Id /// </summary> /// <param name="appId"></param> public void SetApp(int appId) { if (appId == 0) { throw new ArgumentException(nameof(appId)); } //Check if app exists var bytesAppIds = KeyValueStore.Get(KeyValueStore.DefaultType, KeyGenerator.AppsKey, null); List <int> appIds = null; if (bytesAppIds != null) { appIds = (List <int>)BinarySerializerHelper.DeserializeObject(bytesAppIds); } if (appIds == null || !appIds.Contains(appId)) { throw new ArgumentException($"{nameof(appId)} - doesn't exist"); } AppId = appId; ForkProvider = new ForkProvider <TDataTypesEnum>(KeyValueStore, AppId); }
public List <DTOs.App> GetApps() { var bytesAppIds = KeyValueStore.Get(KeyValueStore.DefaultType, KeyGenerator.AppsKey, null); List <int> appIds = null; if (bytesAppIds == null) { return(new List <DTOs.App>()); } appIds = (List <int>)BinarySerializerHelper.DeserializeObject(bytesAppIds); var res = new List <DTOs.App>(); foreach (var appId in appIds) { var bytesApp = KeyValueStore.Get(KeyValueStore.DefaultType, KeyGenerator.GenerateAppKey(appId), null); if (bytesApp == null) { continue; } var app = ProtoBufSerializerHelper.Deserialize <App>(bytesApp); res.Add(new DTOs.App { Id = app.Id, Name = app.Name, Description = app.Description }); } return(res); }
public IEnumerator C_非プリミティブ型の値を取得できる() { var customClass = new CustomClass(10, "custom class"); var dateTimeNow = DateTime.Now; PlayerPrefs.SetString(Key + "Custom", Serializer.Default(customClass)); PlayerPrefs.SetString(Key + "DateTime", Serializer.DateTime(dateTimeNow)); yield return(KeyValueStore .Get(Key + "Custom", deserializeCallback: Deserializer.Default <CustomClass>) .ToCoroutine( x => { Assert.That(x.IntValue, Is.EqualTo(customClass.IntValue)); Assert.That(x.StringValue, Is.EqualTo(customClass.StringValue)); } )); yield return(KeyValueStore .Get(Key + "DateTime", deserializeCallback: Deserializer.DateTime) .ToCoroutine( x => { Assert.That(x.Year, Is.EqualTo(dateTimeNow.Year)); Assert.That(x.Month, Is.EqualTo(dateTimeNow.Month)); Assert.That(x.Day, Is.EqualTo(dateTimeNow.Day)); Assert.That(x.Hour, Is.EqualTo(dateTimeNow.Hour)); Assert.That(x.Minute, Is.EqualTo(dateTimeNow.Minute)); Assert.That(x.Second, Is.EqualTo(dateTimeNow.Second)); } )); }
private void RemoveNode(T nodeId) { if (!store.ContainsKey(nodeId)) { return; } uint[] keys = null; List <Point> points = null; try { lock (locker) { points = new List <Point>(circle); keys = store.Get(nodeId).ToArray(); store.Remove(nodeId); if (keys.IsNullOrEmpty()) { return; } points.RemoveAll(v => keys.Contains(v.key)); points.Sort(compare); circle = points; } } finally { keys = null; points = null; } }
public void LargeDataSetGetTest() { string path = Path.GetFullPath("TestData\\LargeDataSetGetTest"); int totalSize = 0; int num_items = 500; var timer = new Stopwatch(); using (var db = new KeyValueStore(path)) { db.Truncate(); // Generate a data value that is larger than the block size. var value = ByteArray.Random(Config.SortedBlockSize + 256); // Do it enough times to ensure a roll-over for (int i = 0; i < num_items; i++) { var key = BitConverter.GetBytes(i); db.Set(key, value.InternalBytes); totalSize += value.InternalBytes.Length; } timer.Start(); for (int i = 0; i < num_items; i++) { var key = BitConverter.GetBytes(i); Assert.AreEqual(value.InternalBytes, db.Get(key)); } timer.Stop(); Console.WriteLine("Randomized read throughput of {0} MB/s (avg {1} ms per lookup)", (double)totalSize / timer.Elapsed.TotalSeconds / (1024.0 * 1024.0), (double)timer.Elapsed.TotalSeconds / (double)num_items); } }
public override string DoProcess(Request request) { var redisObject = store.Get(request.args[0]); var valToIncBy = long.Parse(request.args[1]); if (redisObject == null) { var redisString = new RedisString("0"); long longValue; redisString.IncrementBy(valToIncBy, out longValue); store.Set(request.args[0], redisString); return(Reply.IntgerReply(longValue)); } if (!redisObject.IsRedisString()) { return(Reply.ErrWrongType()); } var s = redisObject as RedisString; if (s.IsConvertibleToLong()) { long longValue; var success = s.IncrementBy(valToIncBy, out longValue); return(success ? Reply.IntgerReply(longValue) : Reply.OverFlow()); } return(Reply.ValueNotInt()); }
public IEnumerator D_デフォルト値を取得できる() { yield return(KeyValueStore .Get(Key, "デフォルト値を取得") .ToCoroutine( x => Assert.That(x, Is.EqualTo("デフォルト値を取得")) )); }
public Archive FindArchive(Hash hash) { if (_archiveEntries.ContainsKey(hash)) { return(_archiveEntries.Get(hash)); } return(null); }
public byte[] ReadArchiveBlock(Archive archive, int blockIndex) { Throw.IfNull(archive, nameof(archive)); Throw.If(blockIndex < 0 || blockIndex >= archive.BlockCount, "invalid block index"); var hash = archive.MerkleTree.GetHash(blockIndex); return(_archiveContents.Get(hash)); }
public void Delete() { foreach (var(key, expectedValue) in PreStoredDataKeys.Zip( PreStoredDataValues, ValueTuple.Create)) { var actual = KeyValueStore.Get(key); Assert.Equal(expectedValue, actual); } }
public void Set() { var key = new KeyBytes(Random.NextBytes(PreStoredDataKeySize)); byte[] value = Random.NextBytes(PreStoredDataValueSize); KeyValueStore.Set(key, value); Assert.Equal(value, KeyValueStore.Get(key)); }
public IEnumerator A_値を取得できる() { PlayerPrefs.SetString(Key, "値を取得"); yield return(KeyValueStore .Get <string>(Key) .ToCoroutine( x => Assert.That(x, Is.EqualTo("値を取得")) )); }
public IEnumerator Getterをキャンセル() { var source = new CancellationTokenSource(); AsyncGetter.When(x => x.GetAsync <int>(Key, cancellationToken: source.Token)).Do(_ => source.Cancel()); yield return(KeyValueStore.Get <int>(Key, cancellationToken: source.Token).ToCoroutine()); Assert.That(source.IsCancellationRequested, Is.True); }
public void Get() { foreach (var(key, expectedValue) in PreStoredDataKeys.Zip( PreStoredDataValues, ValueTuple.Create)) { var actual = KeyValueStore.Get(key); Assert.Equal(expectedValue, actual); } var randomKey = NewRandomKey(); Assert.Throws <KeyNotFoundException>(() => KeyValueStore.Get(randomKey)); }
public void CanInsertAndGetByOffset() { // ARRANGE var pair1 = new KeyValuePair <string, string>("addr", "eic"); var pair2 = new KeyValuePair <string, string>("addr", "inv"); // ACT _store.Insert(pair1, 0); var offset = _store.Insert(pair2, 0); var result = _store.Get(offset); // ASSERT Assert.AreEqual(pair2, result); }
public override string DoProcess(Request request) { var redisObject = store.Get(request.args[0]); if (redisObject == null) { return(Reply.Nil()); } if (!redisObject.IsRedisString()) { return(Reply.ErrWrongType()); } return(Reply.BulkReply(redisObject.ToString())); }
public void Overwrite() { foreach (var(key, expectedValue) in PreStoredDataKeys.Zip( PreStoredDataValues, ValueTuple.Create)) { var randomValue = Random.NextBytes(PreStoredDataValueSize); var actual = KeyValueStore.Get(key); Assert.Equal(expectedValue, actual); KeyValueStore.Set(key, randomValue); actual = KeyValueStore.Get(key); Assert.Equal(randomValue, actual); Assert.NotEqual(expectedValue, actual); } }
public void GetMany() { KeyBytes[] nonExistentKeys = Enumerable.Range(0, 10) .Select(_ => NewRandomKey()) .ToArray(); KeyBytes[] keys = PreStoredDataKeys .Concat(PreStoredDataKeys.Take(PreStoredDataCount / 2)) .Concat(nonExistentKeys) .ToArray(); IReadOnlyDictionary <KeyBytes, byte[]> result = KeyValueStore.Get(keys); Assert.Equal(PreStoredDataCount, result.Count); Assert.All(PreStoredDataKeys, k => Assert.Contains(k, result)); Assert.All(nonExistentKeys, k => Assert.DoesNotContain(k, result)); }
public override string DoProcess(Request request) { var redisObject = store.Get(request.args[0]); if (redisObject == null) { return(Reply.IntgerReply(0)); } if (!redisObject.IsRedisString()) { return(Reply.ErrWrongType()); } return(Reply.IntgerReply((redisObject as RedisString).Length())); }
public override string DoProcess(Request request) { var redisObject = store.Get(request.args[0]); if (redisObject == null) { return(Reply.BulkReply("")); } if (!redisObject.IsRedisString()) { return(Reply.ErrWrongType()); } return(Reply.BulkReply((redisObject as RedisString).Substring(int.Parse(request.args[1]), int.Parse(request.args[2])))); }
private ForkRawData GetFork(int id) { if (id == 0) { throw new ArgumentNullException(nameof(id)); } var forkData = KeyValueStore.Get(KeyValueStore.DefaultType, KeyGenerator.GenerateForkKey(AppId, id), null); if (forkData == null) { throw new ArgumentException($"Fork id:{id} doesn't reference actual fork"); } return(ProtoBufSerializerHelper.Deserialize <ForkRawData>(forkData)); }
public void SetMany() { var values = new Dictionary <KeyBytes, byte[]>(); foreach (int i in Enumerable.Range(0, 10)) { values[new KeyBytes(Random.NextBytes(PreStoredDataKeySize))] = Random.NextBytes(PreStoredDataValueSize); } KeyValueStore.Set(values); foreach (KeyValuePair <KeyBytes, byte[]> kv in values) { Assert.Equal(kv.Value, KeyValueStore.Get(kv.Key)); } }
public override string DoProcess(Request request) { var redisObject = store.Get(request.args[0]); if (redisObject == null) { var redisString = new RedisString(request.args[1]); store.Set(request.args[0], redisString); return(Reply.IntgerReply(redisString.Length())); } if (!redisObject.IsRedisString()) { return(Reply.ErrWrongType()); } var s = redisObject as RedisString; s.Append(request.args[1]); return(Reply.IntgerReply(s.Length())); }
public IEnumerator 基本メソッド() { yield return(KeyValueStore .Has(Key) .ToCoroutine(x => Assert.That(x, Is.False))); yield return(KeyValueStore .Get(Key, "DefaultValue") .ToCoroutine(x => Assert.That(x, Is.EqualTo("DefaultValue")))); yield return(KeyValueStore .Set(Key, "NewValue") .ToCoroutine()); yield return(KeyValueStore .Has(Key) .ToCoroutine(x => Assert.That(x, Is.True))); yield return(KeyValueStore .Get <string>(Key) .ToCoroutine(x => Assert.That(x, Is.EqualTo("NewValue")))); }
public void TestLargeAndSmallOddWrites() { string path = Path.GetFullPath("TestData\\TestLargeAndSmallInterlacedWrites"); using (var db = new KeyValueStore(path)) { db.Truncate(); // Create a random set of keybytes List <byte[]> keys = new List <byte[]>(); for (int i = 0; i < 10; i++) { keys.Add(Key.Random(10).KeyBytes); } // Set Odds to large for (int i = 0; i < keys.Count; i++) { var k = keys[i]; var v = ((i & 1) == 1) ? GenerateBlock(Config.MaxLargeValueSize - 100) : GenerateBlock(10); db.Set(k, v); } // Now check the results for (int i = 0; i < keys.Count; i++) { var k = keys[i]; var v = db.Get(k); CheckBlock(v); if ((i & 1) == 0) { Assert.Less(v.Length, 100, " i = {0} should be small, but size={1}", i, v.Length); } else { Assert.Greater(v.Length, 100, " i = {0} should be large, but size={1}", i, v.Length); } } } }
/// <summary> /// Creates a new app and a master fork /// On success sets the app id /// </summary> /// <param name="appId"></param> /// <param name="name"></param> /// <param name="description"></param> public void CreateApp(int appId, string name, string description) { var bytesAppIds = KeyValueStore.Get(KeyValueStore.DefaultType, KeyGenerator.AppsKey, null); List <int> appIds = null; if (bytesAppIds != null) { appIds = (List <int>)BinarySerializerHelper.DeserializeObject(bytesAppIds); } else { appIds = new List <int>(); KeyValueStore.Set(KeyValueStore.DefaultType, KeyGenerator.AppsKey, BinarySerializerHelper.SerializeObject(appIds), null); } if (appIds.Contains(appId)) { throw new ArgumentException(nameof(appId)); } appIds.Add(appId); KeyValueStore.Set(KeyValueStore.DefaultType, KeyGenerator.AppsKey, BinarySerializerHelper.SerializeObject(appIds), null); var res = new App { Id = appId, Name = name, Description = description }; KeyValueStore.Set(KeyValueStore.DefaultType, KeyGenerator.GenerateAppKey(appId), ProtoBufSerializerHelper.Serialize(res), null); KeyValueStore.Set(KeyValueStore.DefaultType, KeyGenerator.GenerateForksKey(appId), BinarySerializerHelper.SerializeObject(new List <int>()), null); SetApp(appId); CreateMasterFork(); }
public IEnumerator B_プリミティブ型の値を取得できる() { PlayerPrefs.SetInt(Key + "Bool", 1); PlayerPrefs.SetInt(Key + "Int", 2); PlayerPrefs.SetFloat(Key + "Float", 100.0f); PlayerPrefs.SetString(Key + "String", "string value"); yield return(KeyValueStore .Get <bool>(Key + "Bool") .ToCoroutine(x => Assert.That(x, Is.True))); yield return(KeyValueStore .Get <int>(Key + "Int") .ToCoroutine(x => Assert.That(x, Is.EqualTo(2)))); yield return(KeyValueStore .Get <float>(Key + "Float") .ToCoroutine(x => Assert.That(x, Is.EqualTo(100.0f)))); yield return(KeyValueStore .Get <string>(Key + "String") .ToCoroutine(x => Assert.That(x, Is.EqualTo("string value")))); }
public override KeyValueStore <T> .Node Execute(KeyValueStore <T> model) { return(model.Get(Key)); }