public bool IsRegionOverlap(RegionInfo other) { return(BinaryComparer.Equals(Namespace, other.Namespace) && BinaryComparer.Equals(Table, other.Table) && (other.StopKey?.Any() != true || BinaryComparer.Compare(StartKey, other.StopKey) < 0) && (StopKey?.Any() != true || BinaryComparer.Compare(StopKey, other.StartKey) > 0)); }
public void TestEquals() { Assert.IsTrue(BinaryComparer.Equals(null, null)); Assert.IsTrue(BinaryComparer.Equals(new byte[] { }, new byte[] { })); Assert.IsTrue(BinaryComparer.Equals(new byte[] { 1, 2, 3 }, new byte[] { 1, 2, 3 })); Assert.IsFalse(BinaryComparer.Equals(null, new byte[] { 1, 2, 3 })); Assert.IsFalse(BinaryComparer.Equals(new byte[] { 1, 2, 3 }, null)); Assert.IsFalse(BinaryComparer.Equals(new byte[] { 1, 2 }, new byte[] { 1, 2, 3 })); Assert.IsFalse(BinaryComparer.Equals(new byte[] { 1, 2, 3 }, new byte[] { 1, 2 })); }
public static void AssertEquals(IDictionary <Guid, TestInfo> x, IEnumerable <KeyValuePair <Guid, TestInfo> > y) { Dictionary <Guid, TestInfo> copy = new Dictionary <Guid, TestInfo>(x); foreach (KeyValuePair <Guid, TestInfo> item in y) { TestInfo value; Assert.IsTrue(x.TryGetValue(item.Key, out value)); Assert.AreEqual(item.Key, item.Value.MyKey); Assert.AreEqual(item.Value.MyKey, value.MyKey); Assert.AreEqual(item.Value.SetNumber, value.SetNumber); Assert.AreEqual(item.Value.CreateOrder, value.CreateOrder); Assert.IsTrue(BinaryComparer.Equals(item.Value.RandomBytes, value.RandomBytes)); Assert.IsTrue(copy.Remove(item.Key)); } Assert.IsEmpty(copy); }
private RegionInfo GetInfoFromCache(byte[] table, byte[] key) { if (BinaryComparer.Compare(table, _metaTableName) == 0) { return(_metaRegionInfo); } var search = RegionInfo.CreateRegionSearchKey(table, key); var info = _cache.GetInfo(search); if (info == null || false == BinaryComparer.Equals(table, info.Table)) { return(null); } if (info.StopKey.Length > 0 && BinaryComparer.Compare(key, info.StopKey) >= 0) { return(null); } return(info); }
public void TestEncryptDecryptStream() { byte[] result; byte[] data = new byte[ushort.MaxValue]; Random rand = new Random(); rand.NextBytes(data); using (MemoryStream final = new MemoryStream()) using (MemoryStream ms = new MemoryStream()) { using (Stream e = Encryptor.Encrypt(new NonClosingStream(ms))) { for (int i = 0; i < data.Length;) { int count = Math.Max(i + 1, Math.Min(data.Length, i + 1 + rand.Next(2000))); e.Write(data, i, count - i); i = count; } e.Flush(); } using (Stream d = Encryptor.Decrypt(new MemoryStream(ms.ToArray()))) { for (int i = 0; i < data.Length;) { int count = Math.Max(i + 1, Math.Min(data.Length, i + 1 + rand.Next(2000))); byte[] tmp = IOStream.Read(d, count - i); final.Write(tmp, 0, tmp.Length); i = count; } } result = final.ToArray(); } Assert.AreEqual(data.Length, result.Length); Assert.IsTrue(BinaryComparer.Equals(data, result)); }