예제 #1
0
        public void TestDestroyPieceResponseReceiveBlockedDuring()
        {
            //given
            var penalizer       = new Penalizer(_samplePenalties);
            var receivedMessage = new Message <DestroyPieceResponse>(
                new DestroyPieceResponse());

            //when
            penalizer.PenalizeOnReceive(receivedMessage);

            //then
            Assert.IsTrue(penalizer.UnderPenalty);
        }
예제 #2
0
        public void TestTwoMessageReceiveStillBlockedAfterSmaller()
        {
            //given
            var penalizer = new Penalizer(_samplePenalties);
            var penaltyNotWaitedMessage = new Message <PenaltyNotWaitedError>(
                new PenaltyNotWaitedError {
                WaitFor = 30
            });
            int penaltyNotWaitedWaitTime = penaltyNotWaitedMessage.MessagePayload.WaitFor;
            var moveMessage = new Message <MoveResponse>(
                new MoveResponse());
            int moveWaitTime = Int32.Parse(_samplePenalties.Move);
            int waitTime     = Math.Min(moveWaitTime, penaltyNotWaitedWaitTime);


            //when
            penalizer.PenalizeOnReceive(penaltyNotWaitedMessage);
            penalizer.PenalizeOnReceive(moveMessage);

            //then
            Thread.Sleep(waitTime);
            Assert.IsTrue(penalizer.UnderPenalty);
        }
예제 #3
0
        public void TestDiscoveryResponseReceiveFreeAfter()
        {
            //given
            var penalizer       = new Penalizer(_samplePenalties);
            var receivedMessage = new Message <DiscoveryResponse>(
                new DiscoveryResponse());
            int waitTime = Int32.Parse(_samplePenalties.Discovery);

            //when
            penalizer.PenalizeOnReceive(receivedMessage);

            //then
            Thread.Sleep(waitTime);
            Assert.IsFalse(penalizer.UnderPenalty);
        }
예제 #4
0
        public void TestCheckPieceResponseReceiveFreeAfter()
        {
            //given
            var penalizer       = new Penalizer(_samplePenalties);
            var receivedMessage = new Message <CheckHoldedPieceResponse>(
                new CheckHoldedPieceResponse());
            int waitTime = Int32.Parse(_samplePenalties.CheckForSham);

            //when
            penalizer.PenalizeOnReceive(receivedMessage);

            //then
            Thread.Sleep(waitTime);
            Assert.IsFalse(penalizer.UnderPenalty);
        }
예제 #5
0
        public void TestPenaltyNotWaitedReceiveBlockedBefore()
        {
            //given
            var penalizer       = new Penalizer(_samplePenalties);
            var receivedMessage = new Message <PenaltyNotWaitedError>(
                new PenaltyNotWaitedError {
                WaitFor = 100
            });
            int waitTime = receivedMessage.MessagePayload.WaitFor;

            //when
            penalizer.PenalizeOnReceive(receivedMessage);

            //then
            Thread.Sleep(waitTime / 2);
            Assert.IsTrue(penalizer.UnderPenalty);
        }
예제 #6
0
        public void TestPenaltyNotWaitedReceiveFreeAfter()
        {
            //given
            var penalizer       = new Penalizer(_samplePenalties);
            var receivedMessage = new Message <PenaltyNotWaitedError>(
                new PenaltyNotWaitedError {
                WaitFor = 30
            });
            int waitTime = receivedMessage.MessagePayload.WaitFor + 10;//precision (from documentation)

            //when
            penalizer.PenalizeOnReceive(receivedMessage);

            //then
            Thread.Sleep(waitTime);
            Assert.IsFalse(penalizer.UnderPenalty);
        }
예제 #7
0
        public void TestFreeAfterStandardRequestResponseAndTimeout()
        {
            //given
            var penalizer        = new Penalizer(_samplePenalties);
            var discoveryRequest = new Message <DiscoveryRequest>(
                new DiscoveryRequest());
            var discoveryResponse = new Message <DiscoveryResponse>(
                new DiscoveryResponse());
            int waitTime = Int32.Parse(_samplePenalties.Discovery);


            //when
            penalizer.PenalizeOnSend(discoveryRequest);
            Thread.Sleep(waitTime);
            penalizer.PenalizeOnReceive(discoveryResponse);

            //then
            Thread.Sleep(waitTime);
            Assert.IsFalse(penalizer.UnderPenalty);
        }
예제 #8
0
        public void TestPutPieceResponseReceiveBlockedDuring()
        {
            //given
            var penalizer       = new Penalizer(_samplePenalties);
            var receivedMessage = new Message <PutPieceResponse>(
                new PutPieceResponse());
            //checking after half of wait time only in one test because:
            //if penalty to wait is to slow then during the time it takes to execute
            //instructions before assert penalty could be over

            //longer penalty only in one test otherwise all tests would take too long
            int waitTime = Int32.Parse(_samplePenalties.PutPiece);

            //when
            penalizer.PenalizeOnReceive(receivedMessage);

            //then
            Thread.Sleep(waitTime / 2);
            Assert.IsTrue(penalizer.UnderPenalty);
        }
예제 #9
0
        public void TestSendAndReceiveStillBlockedAfterSmaller()
        {
            //given
            var penalizer       = new Penalizer(_samplePenalties);
            var exchangeRequest = new Message <ExchangeInformationRequest>(
                new ExchangeInformationRequest());
            int exchangeWaitTime = Int32.Parse(_samplePenalties.InformationExchange);
            var moveMessage      = new Message <MoveResponse>(
                new MoveResponse());
            int moveWaitTime = Int32.Parse(_samplePenalties.Move);
            int waitTime     = Math.Min(moveWaitTime, exchangeWaitTime);


            //when
            penalizer.PenalizeOnSend(exchangeRequest);
            penalizer.PenalizeOnReceive(moveMessage);

            //then
            Thread.Sleep(waitTime);
            Assert.IsTrue(penalizer.UnderPenalty);
        }