UpdateEntry() public method

This should be called if an entry already exists as it will find the entry and update its lease time. If an entry does not exist nothing happens.
public UpdateEntry ( MemBlock key, MemBlock value, DateTime end_time ) : void
key MemBlock The index to store the value.
value MemBlock The data to store.
end_time DateTime The lease time for the data.
return void
示例#1
0
        public void Test0()
        {
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            TableServerData          tsd = new TableServerData("0");

            byte[] key = new byte[20];
            rng.GetBytes(key);
            DateTime now = DateTime.UtcNow;
            Entry    ent = new Entry(key, key, now, now.AddSeconds(100));

            tsd.AddEntry(ent);
            LinkedList <Entry> entries = tsd.GetEntries(key);

            Assert.AreEqual(1, entries.Count, "Count after add");
            Assert.AreEqual(ent, entries.First.Value, "Entries are equal");
            tsd.UpdateEntry(ent.Key, ent.Value, now.AddSeconds(200));
            entries = tsd.GetEntries(key);
            Assert.AreEqual(1, entries.Count, "Count after update");
            Assert.AreEqual(ent, entries.First.Value, "Entries are equal");
            tsd.RemoveEntry(ent.Key, ent.Value);
            entries = tsd.GetEntries(key);
            Assert.AreEqual(tsd.Count, 0, "Count after remove");
            Assert.AreEqual(null, entries, "Entry after remove");
        }
示例#2
0
        public void Test1()
        {
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            TableServerData          tsd = new TableServerData("0");

            Entry[]  not_expired = new Entry[12];
            Entry[]  to_expire   = new Entry[12];
            DateTime now         = DateTime.UtcNow;
            DateTime live        = now.AddSeconds(120);
            DateTime expire      = now.AddSeconds(5);

            for (int i = 0; i < 4; i++)
            {
                byte[] key = new byte[20];
                rng.GetBytes(key);
                for (int j = 0; j < 3; j++)
                {
                    byte[] value = new byte[20];
                    rng.GetBytes(value);
                    Entry ent = new Entry(key, value, now, expire);
                    to_expire[i * 3 + j] = ent;
                    tsd.AddEntry(ent);
                    value = new byte[20];
                    rng.GetBytes(value);
                    ent = new Entry(key, value, now, live);
                    not_expired[i * 3 + j] = ent;
                    tsd.AddEntry(ent);
                    Assert.IsFalse(not_expired[i * 3 + j].Equals(to_expire[i * 3 + j]),
                                   String.Format("{0}: not_expired == to_expire.", i * 3 + j));
                }
            }

            for (int i = 0; i < 4; i++)
            {
                LinkedList <Entry> entries = tsd.GetEntries(not_expired[i * 3].Key);
                for (int j = 0; j < 3; j++)
                {
                    Assert.IsTrue(entries.Contains(not_expired[i * 3 + j]), "step 0: not_expired " + (i * 3 + j));
                    Assert.IsTrue(entries.Contains(to_expire[i * 3 + j]), "step 0: to_expire " + (i * 3 + j));
                }
            }

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    int pos = i * 3 + j;
                    if (pos % 2 == 0)
                    {
                        Entry ent = not_expired[pos];
                        tsd.UpdateEntry(ent.Key, ent.Value, now.AddSeconds(160));
                    }
                }
            }

            Entry entry = to_expire[11];

            tsd.UpdateEntry(entry.Key, entry.Value, now.AddSeconds(160));

            for (int i = 0; i < 4; i++)
            {
                LinkedList <Entry> entries = tsd.GetEntries(not_expired[i * 3].Key);
                for (int j = 0; j < 3; j++)
                {
                    Assert.IsTrue(entries.Contains(not_expired[i * 3 + j]), "step 1: not_expired " + (i * 3 + j));
                    Assert.IsTrue(entries.Contains(to_expire[i * 3 + j]), "step 1: to_expire " + (i * 3 + j));
                }
            }

            while (DateTime.UtcNow < expire.AddSeconds(1))
            {
                for (int i = 0; i < 50000000; i++)
                {
                    int k = i % 5;
                    k += 6;
                }
            }
            for (int i = 0; i < 3; i++)
            {
                LinkedList <Entry> entries = tsd.GetEntries(not_expired[i * 3].Key);
                for (int j = 0; j < 3; j++)
                {
                    Assert.IsTrue(entries.Contains(not_expired[i * 3 + j]), "step 2: not_expired " + (i * 3 + j));
                    Assert.IsFalse(entries.Contains(to_expire[i * 3 + j]), "step 2: to_expire " + (i * 3 + j));
                }
            }
            Assert.AreEqual(13, tsd.Count, "Entries we didn't check are removed by CheckEntries.");
        }
示例#3
0
    public void Test1() {
      RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
      TableServerData tsd = new TableServerData("0");
      Entry[] not_expired = new Entry[12];
      Entry[] to_expire = new Entry[12];
      DateTime now = DateTime.UtcNow;
      DateTime live = now.AddSeconds(120);
      DateTime expire = now.AddSeconds(5);

      for(int i = 0; i < 4; i++) {
        byte[] key = new byte[20];
        rng.GetBytes(key);
        for(int j = 0; j < 3; j++) {
          byte[] value = new byte[20];
          rng.GetBytes(value);
          Entry ent = new Entry(key, value, now, expire);
          to_expire[i * 3 + j] = ent;
          tsd.AddEntry(ent);
          value = new byte[20];
          rng.GetBytes(value);
          ent = new Entry(key, value, now, live);
          not_expired[i * 3 + j] = ent;
          tsd.AddEntry(ent);
          Assert.IsFalse(not_expired[i * 3 + j].Equals(to_expire[i * 3 + j]), 
                         String.Format("{0}: not_expired == to_expire.", i * 3 + j));
        }
      }

      for(int i = 0; i < 4; i++) {
        LinkedList<Entry> entries = tsd.GetEntries(not_expired[i * 3].Key);
        for(int j = 0; j < 3; j++) {
          Assert.IsTrue(entries.Contains(not_expired[i * 3 + j]), "step 0: not_expired " + (i * 3 + j));
          Assert.IsTrue(entries.Contains(to_expire[i * 3 + j]), "step 0: to_expire " + (i * 3 + j));
        }
      }

      for(int i = 0; i < 4; i++) {
        for(int j = 0; j < 3; j++) {
          int pos = i * 3 + j;
          if(pos % 2 == 0) {
            Entry ent = not_expired[pos];
            tsd.UpdateEntry(ent.Key, ent.Value, now.AddSeconds(160));
          }
        }
      }

      Entry entry = to_expire[11];
      tsd.UpdateEntry(entry.Key, entry.Value, now.AddSeconds(160));

      for(int i = 0; i < 4; i++) {
        LinkedList<Entry> entries = tsd.GetEntries(not_expired[i * 3].Key);
        for(int j = 0; j < 3; j++) {
          Assert.IsTrue(entries.Contains(not_expired[i * 3 + j]), "step 1: not_expired " + (i * 3 + j));
          Assert.IsTrue(entries.Contains(to_expire[i * 3 + j]), "step 1: to_expire " + (i * 3 + j));
        }
      }

      while(DateTime.UtcNow < expire.AddSeconds(1)) {
        for(int i = 0; i < 50000000; i++) {
          int k = i % 5;
         k += 6;
        }
      }
      for(int i = 0; i < 3; i++) {
        LinkedList<Entry> entries = tsd.GetEntries(not_expired[i * 3].Key);
        for(int j = 0; j < 3; j++) {
          Assert.IsTrue(entries.Contains(not_expired[i * 3 + j]), "step 2: not_expired " + (i * 3 + j));
          Assert.IsFalse(entries.Contains(to_expire[i * 3 + j]), "step 2: to_expire " + (i * 3 + j));
        }
      }
      Assert.AreEqual(13, tsd.Count, "Entries we didn't check are removed by CheckEntries.");
    }
示例#4
0
 public void Test0() {
   RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
   TableServerData tsd = new TableServerData("0");
   byte[] key = new byte[20];
   rng.GetBytes(key);
   DateTime now = DateTime.UtcNow;
   Entry ent = new Entry(key, key, now, now.AddSeconds(100));
   tsd.AddEntry(ent);
   LinkedList<Entry> entries = tsd.GetEntries(key);
   Assert.AreEqual(1, entries.Count, "Count after add");
   Assert.AreEqual(ent, entries.First.Value, "Entries are equal");
   tsd.UpdateEntry(ent.Key, ent.Value, now.AddSeconds(200));
   entries = tsd.GetEntries(key);
   Assert.AreEqual(1, entries.Count, "Count after update");
   Assert.AreEqual(ent, entries.First.Value, "Entries are equal");
   tsd.RemoveEntry(ent.Key, ent.Value);
   entries = tsd.GetEntries(key);
   Assert.AreEqual(tsd.Count, 0, "Count after remove");
   Assert.AreEqual(null, entries, "Entry after remove");
 }