public void TestPutChunkMessage() { var msg = new PutChunkMessage(1, 0, FileId1, 50, 5, Body1); Assert.AreEqual(MessageType.PutChunk, msg.MessageType); Assert.AreEqual(1, msg.VersionM); Assert.AreEqual(0, msg.VersionN); Assert.AreEqual("1.0", msg.GetVersion()); Assert.AreEqual(FileId1, msg.FileId); Assert.AreEqual(50, msg.ChunkNo); Assert.AreEqual(5, msg.ReplicationDeg); CollectionAssert.AreEqual(Body1, msg.Body); }
private void SendChunk() { var timeout = Core.Instance.Config.BackupChunkTimeout; var maxRetries = Core.Instance.Config.BackupChunkRetries; var multi = Core.Instance.Config.BackupChunkTimeoutMultiplier; int retryCount; var success = false; var count = 0; for (retryCount = 0; retryCount < maxRetries; retryCount++) { var msg = new PutChunkMessage(_fileChunk, _replicationDegree, _data); Core.Instance.MDBChannel.Send(msg); Task.Delay(timeout).Wait(); count = Core.Instance.ChunkPeers.CountChunkPeer(_fileChunk); if (count >= _replicationDegree) { success = true; break; } timeout = (int)(timeout * multi); if (retryCount != maxRetries - 1) // not last iter { Core.Instance.Log.InfoFormat("{0}: ChunkReplication degree is {1} but wanted {2}. Timeout increased to {3}", _fileChunk, count, _replicationDegree, timeout); } } Core.Instance.Log.InfoFormat( success ? "{0}: Stored: retries {1}, rep degree {2}" : "{0}: Giving up: retries {1}, rep degree {2}", _fileChunk, retryCount, count); }
public void TestMessageFieldUpperBounds() { var body = new byte[255]; for (var i = 0; i < body.Length; ++i) { body[i] = (byte)i; } var getChunkMsg = new GetChunkMessage(9, 9, FileId1, 999999); var bytes = getChunkMsg.Serialize(); var getChunkMsg2 = Message.Deserialize(bytes) as GetChunkMessage; Assert.IsNotNull(getChunkMsg2); Assert.AreEqual(getChunkMsg.MessageType, getChunkMsg2.MessageType); Assert.AreEqual(getChunkMsg.VersionM, getChunkMsg2.VersionM); Assert.AreEqual(getChunkMsg.VersionN, getChunkMsg2.VersionN); Assert.AreEqual(getChunkMsg.FileId, getChunkMsg2.FileId); Assert.AreEqual(getChunkMsg.ChunkNo, getChunkMsg2.ChunkNo); var chunkMsg = new ChunkMessage(9, 9, FileId1, 999999, body); bytes = chunkMsg.Serialize(); var chunkMsg2 = Message.Deserialize(bytes) as ChunkMessage; Assert.IsNotNull(chunkMsg2); Assert.AreEqual(chunkMsg.MessageType, chunkMsg2.MessageType); Assert.AreEqual(chunkMsg.VersionM, chunkMsg2.VersionM); Assert.AreEqual(chunkMsg.VersionN, chunkMsg2.VersionN); Assert.AreEqual(chunkMsg.FileId, chunkMsg2.FileId); Assert.AreEqual(chunkMsg.ChunkNo, chunkMsg2.ChunkNo); CollectionAssert.AreEqual(chunkMsg.Body, chunkMsg2.Body); var putChunkMsg = new PutChunkMessage(9, 9, FileId1, 999999, 9, body); bytes = putChunkMsg.Serialize(); var putChunkMsg2 = Message.Deserialize(bytes) as PutChunkMessage; Assert.IsNotNull(putChunkMsg2); Assert.AreEqual(putChunkMsg.MessageType, putChunkMsg2.MessageType); Assert.AreEqual(putChunkMsg.VersionM, putChunkMsg2.VersionM); Assert.AreEqual(putChunkMsg.VersionN, putChunkMsg2.VersionN); Assert.AreEqual(putChunkMsg.FileId, putChunkMsg2.FileId); Assert.AreEqual(putChunkMsg.ChunkNo, putChunkMsg2.ChunkNo); Assert.AreEqual(putChunkMsg.ReplicationDeg, putChunkMsg2.ReplicationDeg); CollectionAssert.AreEqual(putChunkMsg.Body, putChunkMsg2.Body); var storedMsg = new StoredMessage(9, 9, FileId1, 999999); bytes = storedMsg.Serialize(); var storedMsg2 = Message.Deserialize(bytes) as StoredMessage; Assert.IsNotNull(storedMsg2); Assert.AreEqual(storedMsg.MessageType, storedMsg2.MessageType); Assert.AreEqual(storedMsg.VersionM, storedMsg2.VersionM); Assert.AreEqual(storedMsg.VersionN, storedMsg2.VersionN); Assert.AreEqual(storedMsg.FileId, storedMsg2.FileId); Assert.AreEqual(storedMsg.ChunkNo, storedMsg2.ChunkNo); var deleteMsg = new DeleteMessage(FileId1); bytes = deleteMsg.Serialize(); var deleteMsg2 = Message.Deserialize(bytes) as DeleteMessage; Assert.IsNotNull(deleteMsg2); Assert.AreEqual(deleteMsg.MessageType, deleteMsg2.MessageType); var removedMsg = new RemovedMessage(9, 9, FileId1, 999999); bytes = removedMsg.Serialize(); var removedMsg2 = Message.Deserialize(bytes) as RemovedMessage; Assert.IsNotNull(removedMsg2); Assert.AreEqual(removedMsg.MessageType, removedMsg2.MessageType); Assert.AreEqual(removedMsg.VersionM, removedMsg2.VersionM); Assert.AreEqual(removedMsg.VersionN, removedMsg2.VersionN); Assert.AreEqual(removedMsg.FileId, removedMsg2.FileId); Assert.AreEqual(removedMsg.ChunkNo, removedMsg2.ChunkNo); var lookupMsg = new LookupMessage(9, 9, FileId1); bytes = lookupMsg.Serialize(); var lookupMsg2 = Message.Deserialize(bytes) as LookupMessage; Assert.IsNotNull(lookupMsg2); Assert.AreEqual(lookupMsg.MessageType, lookupMsg2.MessageType); Assert.AreEqual(lookupMsg.VersionM, lookupMsg2.VersionM); Assert.AreEqual(lookupMsg.VersionN, lookupMsg2.VersionN); Assert.AreEqual(lookupMsg.FileId, lookupMsg2.FileId); var gotMsg = new GotMessage(9, 9, FileId1); bytes = gotMsg.Serialize(); var gotMsg2 = Message.Deserialize(bytes) as GotMessage; Assert.IsNotNull(gotMsg2); Assert.AreEqual(gotMsg.MessageType, gotMsg2.MessageType); Assert.AreEqual(gotMsg.VersionM, gotMsg2.VersionM); Assert.AreEqual(gotMsg.VersionN, gotMsg2.VersionN); Assert.AreEqual(gotMsg.FileId, gotMsg2.FileId); var ackMsg = new ACKMessage(9, 9, FileId1, 999999); bytes = ackMsg.Serialize(); var ackMsg2 = Message.Deserialize(bytes) as ACKMessage; Assert.IsNotNull(ackMsg2); Assert.AreEqual(ackMsg.MessageType, ackMsg2.MessageType); Assert.AreEqual(ackMsg.VersionM, ackMsg2.VersionM); Assert.AreEqual(ackMsg.VersionN, ackMsg2.VersionN); Assert.AreEqual(ackMsg.FileId, ackMsg2.FileId); Assert.AreEqual(ackMsg.ChunkNo, ackMsg2.ChunkNo); }