public void InterningWorks() { InternedBlob keyFoo = new InternedBlob("foo"); InternedBlob keyBar = new InternedBlob("bar"); InternedBlob keyFoo2 = new InternedBlob(bytesFoo); Assert.Equal("foo", keyFoo2.ToString()); // Self Assert.True(keyFoo.Equals(keyFoo)); Assert.True(keyFoo.Equals((InternedBlobRef)keyFoo)); Assert.True(keyFoo.Equals((object)keyFoo)); Assert.True(keyFoo.Equals(keyFoo.AsBlobRef())); // Similar Assert.True(keyFoo.Equals(keyFoo2)); Assert.True(keyFoo.Equals((object)keyFoo2)); Assert.True(keyFoo.Equals((InternedBlobRef)keyFoo2)); Assert.True(keyFoo.Equals(keyFoo2.AsBlobRef())); // Different Assert.False(keyFoo.Equals(keyBar)); Assert.False(keyFoo.Equals((object)keyBar)); Assert.False(keyFoo.Equals((InternedBlobRef)keyBar)); Assert.False(keyFoo.Equals(keyBar.AsBlobRef())); }
public override UpdateResult Update() { // For this example, we are processing all updates. // Normally clients can limit how much they are willing to process per frame. StateSnapshot snapshot; for (bool hasMoreUpdates = true; hasMoreUpdates;) { (snapshot, hasMoreUpdates) = _replicatedState.ProcessSingleUpdate(this); } switch (testStage) { case TestStage.WantsToCreateAnObject: TransactionBuilder transactionBuilder = new TransactionBuilder(); createdObjectGuid = Guid.NewGuid(); createdObjectKey = MakeObjectKey(createdObjectGuid); transactionBuilder.RequireSubkeysCount(createdObjectKey, 0); transactionBuilder.Put(createdObjectKey, 0, new byte[] { 1, 2, 3 }); transactionBuilder.Put(createdObjectKey, 1, new byte[] { 4, 5, 6 }); transactionBuilder.Put(createdObjectKey, 2, new byte[] { 7, 8, 9 }); Transaction transaction = transactionBuilder.CreateTransaction(); _replicatedState.Commit(transaction); testStage = TestStage.WaitingForModificationByOtherClient; return(UpdateResult.SentTransaction); // TODO: make the exchange more exciting by adding more states } return(UpdateResult.NothingHappened); }
public override UpdateResult Update() { // For this example, we are processing all updates. // Normally clients can limit how much they are willing to process per frame. StateSnapshot snapshot; for (bool hasMoreUpdates = true; hasMoreUpdates;) { (snapshot, hasMoreUpdates) = _replicatedState.ProcessSingleUpdate(this); } switch (testStage) { case TestStage.WaitingForObjectsToAppear: if (_objects.Count != 0) { TransactionBuilder transactionBuilder = new TransactionBuilder(); foreach (KeyValuePair <Guid, SomeObject> value in _objects) { InternedBlob key = MakeObjectKey(value.Key); transactionBuilder.Put(key, 0, new byte[] { 0, 0, 0 }); } Transaction transaction = transactionBuilder.CreateTransaction(); _replicatedState.Commit(transaction); testStage = TestStage.Done; return(UpdateResult.SentTransaction); } break; // TODO: make the exchange more exciting by adding more states } return(UpdateResult.NothingHappened); }
public void HashesAreExpected() { InternedBlob keyFoo = new InternedBlob("foo"); Assert.Equal(0xCA796135, (uint)keyFoo.GetHashCode()); Assert.Equal(0x836E8217CA796135ul, keyFoo.Hash); InternedBlob keyBar = new InternedBlob("bar"); Assert.Equal(0x562585D9, keyBar.GetHashCode()); Assert.Equal(0x6E84777F562585D9ul, keyBar.Hash); InternedBlob keyWithZeros = new InternedBlob(bytesWithZeros); Assert.Equal(0x6B4EE12F, keyWithZeros.GetHashCode()); Assert.Equal(0x8F5FBB1D6B4EE12Ful, keyWithZeros.Hash); }
public void Create() { // At least for the cases when UTF-8 conversion round trips. InternedBlob keyFoo = new InternedBlob("foo"); Assert.Equal("foo", keyFoo.ToString()); Assert.True(keyFoo.ToSpan().SequenceEqual(bytesFoo)); InternedBlob keyNihao = new InternedBlob("你好"); Assert.Equal("你好", keyNihao.ToString()); Assert.True(keyNihao.ToSpan().SequenceEqual(bytesNihao)); InternedBlob keyWithZeros = new InternedBlob(bytesWithZeros); Assert.True(keyWithZeros.ToSpan().SequenceEqual(bytesWithZeros)); }