Beispiel #1
0
        public string WriteRow(IList <Tuple <string, string> > keys, IDictionary <string, object> data, string eTag)
        {
            if (keys.Count > numKeyLayers)
            {
                var error = string.Format("Wrong number of keys supplied -- Expected count = {0} Received = {1}", numKeyLayers, keys.Count);
                Trace.TraceError(error);
                throw new ArgumentOutOfRangeException("keys", keys.Count, error);
            }

            lock (lockable)
            {
                var storedData = GetDataStore(keys);

                foreach (var kv in data)
                {
                    storedData[kv.Key] = kv.Value;
                }

                Etag = NewEtag();
#if DEBUG
                var storeContents = DumpData(false);
                Trace.TraceInformation("WriteRow: Keys={0} Data={1} Store contents after = {2} New Etag = {3}",
                                       StorageProviderUtils.PrintKeys(keys),
                                       StorageProviderUtils.PrintData(data),
                                       storeContents, Etag);
#endif
                return(Etag);
            }
        }
Beispiel #2
0
        public bool DeleteRow(IList <Tuple <string, string> > keys, string eTag)
        {
            if (keys.Count > numKeyLayers)
            {
                throw new ArgumentOutOfRangeException("keys", keys.Count,
                                                      string.Format("Not enough keys supplied -- Expected count = {0} Received = {1}", numKeyLayers, keys.Count));
            }

            string keyStr = MakeStoreKey(keys);

            bool removedEntry = false;

            lock (lockable)
            {
                IDictionary <string, object> data;
                if (dataTable.TryGetValue(keyStr, out data))
                {
                    var kv = new KeyValuePair <string, IDictionary <string, object> >(keyStr, data);
                    dataTable.Remove(kv);
                    removedEntry = true;
                }

                // No change to Etag
#if DEBUG
                Trace.TraceInformation("DeleteRow: Keys={0} Removed={1} Data={2} Etag={3}",
                                       StorageProviderUtils.PrintKeys(keys),
                                       StorageProviderUtils.PrintData(data),
                                       removedEntry, Etag);
#endif
                return(removedEntry);
            }
        }
Beispiel #3
0
        public void Store_Delete()
        {
            string name = Guid.NewGuid().ToString();//TestContext.TestName;

            ILocalDataStore store = new HierarchicalKeyStore(2);

            GrainReference reference = this.fixture.InternalGrainFactory.GetGrain(LegacyGrainId.NewId());
            var            data      = TestStoreGrainState.NewRandomState();

            output.WriteLine("Using store = {0}", store.GetType().FullName);
            Stopwatch sw = new Stopwatch();

            var keys = GetKeys(name, reference);

            sw.Restart();
            string eTag = store.WriteRow(keys, AsDictionary(data.State), null);

            output.WriteLine("Write returned Etag={0} after {1} {2}", eTag, sw.Elapsed, StorageProviderUtils.PrintOneWrite(keys, data, eTag));

            sw.Restart();
            var storedData = store.ReadRow(keys);

            output.WriteLine("Read returned {0} after {1}", StorageProviderUtils.PrintOneWrite(keys, storedData, eTag), sw.Elapsed);
            Assert.NotNull(data); // Should get some data from Read

            sw.Restart();
            bool ok = store.DeleteRow(keys, eTag);

            Assert.True(ok, $"Row deleted OK after {sw.Elapsed}. Etag={eTag} Keys={StorageProviderUtils.PrintKeys(keys)}");

            sw.Restart();
            storedData = store.ReadRow(keys); // Try to re-read after delete
            output.WriteLine("Re-Read took {0} and returned {1}", sw.Elapsed, StorageProviderUtils.PrintData(storedData));
            Assert.NotNull(data);             // Should not get null data from Re-Read
            Assert.True(storedData.Count == 0, $"Should get no data from Re-Read but got: {StorageProviderUtils.PrintData(storedData)}");

            sw.Restart();
            const string oldEtag = null;

            eTag = store.WriteRow(keys, storedData, oldEtag);
            output.WriteLine("Write for Keys={0} Etag={1} Data={2} returned New Etag={3} after {4}",
                             StorageProviderUtils.PrintKeys(keys), oldEtag, StorageProviderUtils.PrintData(storedData),
                             eTag, sw.Elapsed);

            sw.Restart();
            ok = store.DeleteRow(keys, eTag);
            Assert.True(ok, $"Row deleted OK after {sw.Elapsed}. Etag={eTag} Keys={StorageProviderUtils.PrintKeys(keys)}");
        }
Beispiel #4
0
        public void Store_Delete()
        {
            string name = TestContext.TestName;

            ILocalDataStore store = new HierarchicalKeyStore(2);

            GrainReference reference          = GrainReference.FromGrainId(GrainId.NewId());
            IDictionary <string, object> data = TestStoreGrainState.NewRandomState().AsDictionary();

            Console.WriteLine("Using store = {0}", store.GetType().FullName);
            Stopwatch sw = new Stopwatch();

            var keys = GetKeys(name, reference);

            sw.Restart();
            string eTag = store.WriteRow(keys, data, null);

            Console.WriteLine("Write returned Etag={0} after {1} {2}", eTag, sw.Elapsed, StorageProviderUtils.PrintOneWrite(keys, data, eTag));

            sw.Restart();
            data = store.ReadRow(keys);
            Console.WriteLine("Read returned {0} after {1}", StorageProviderUtils.PrintOneWrite(keys, data, eTag), sw.Elapsed);
            Assert.IsNotNull(data, "Should get some data from Read");

            sw.Restart();
            bool ok = store.DeleteRow(keys, eTag);

            Assert.IsTrue(ok, "Row deleted OK after {0}. Etag={1} Keys={2}", sw.Elapsed, eTag, StorageProviderUtils.PrintKeys(keys));

            sw.Restart();
            data = store.ReadRow(keys); // Try to re-read after delete
            Console.WriteLine("Re-Read took {0} and returned {1}", sw.Elapsed, StorageProviderUtils.PrintData(data));
            Assert.IsNotNull(data, "Should not get null data from Re-Read");
            Assert.IsTrue(data.Count == 0, "Should get no data from Re-Read but got: {0}", StorageProviderUtils.PrintData(data));

            sw.Restart();
            const string oldEtag = null;

            eTag = store.WriteRow(keys, data, oldEtag);
            Console.WriteLine("Write for Keys={0} Etag={1} Data={2} returned New Etag={3} after {4}",
                              StorageProviderUtils.PrintKeys(keys), oldEtag, StorageProviderUtils.PrintData(data),
                              eTag, sw.Elapsed);

            sw.Restart();
            ok = store.DeleteRow(keys, eTag);
            Assert.IsTrue(ok, "Row deleted OK after {0}. Etag={1} Keys={2}", sw.Elapsed, eTag, StorageProviderUtils.PrintKeys(keys));
        }
Beispiel #5
0
        public IDictionary <string, object> ReadRow(IList <Tuple <string, string> > keys)
        {
            if (keys.Count > numKeyLayers)
            {
                var error = string.Format("Not enough keys supplied -- Expected count = {0} Received = {1}", numKeyLayers, keys.Count);
                Trace.TraceError(error);
                throw new ArgumentOutOfRangeException("keys", keys.Count, error);
            }

            lock (lockable)
            {
                IDictionary <string, object> data = GetDataStore(keys);

#if DEBUG
                Trace.TraceInformation("ReadMultiRow: Keys={0} returning Data={1}",
                                       StorageProviderUtils.PrintKeys(keys), StorageProviderUtils.PrintData(data));
#endif
                return(data);
            }
        }
Beispiel #6
0
        public string DumpData(bool printDump = true)
        {
            var sb = new StringBuilder();

            lock (lockable)
            {
                string[] keys = dataTable.Keys.ToArray();
                foreach (var key in keys)
                {
                    var data = dataTable[key];
                    sb.AppendFormat("{0} => {1}", key, StorageProviderUtils.PrintData(data)).AppendLine();
                }
            }
#if !DEBUG
            if (printDump)
#endif
            {
                Trace.TraceInformation("Dump {0} Etag={1} Data= {2}", GetType(), Etag, sb);
            }
            return(sb.ToString());
        }