Beispiel #1
0
        public void CheckpointErrorHandling()
        {
            WriteActions(
                new InitializeAction("0"),
                new ProcessRecordsAction(new DefaultRecord("456", "cat", "bWVvdw==")),
                new CheckpointAction(null)
            {
                Error = "oh noes"
            },
                new ShardEndedAction()
                );

            bool handlerCodeCalled         = false;
            CheckpointErrorHandler handler = (sequenceNumber, errorMsg, checkpointer) =>
            {
                handlerCodeCalled = true;
            };

            TestRecordProcessor recordProcessor = new TestRecordProcessor
            {
                ProcessFunc = (input) => input.Checkpointer.Checkpoint(input.Records.Last(), handler)
            };

            KclProcess.Create(recordProcessor, _ioHandler).Run();

            Assert.IsTrue(handlerCodeCalled);
        }
Beispiel #2
0
        public void NonFatalCheckpointError()
        {
            var  recordProcessor      = Substitute.For <IRecordProcessor>();
            bool madeItPastCheckpoint = false;

            recordProcessor.ProcessRecords(Arg.Do <ProcessRecordsInput>(x =>
            {
                x.Checkpointer.Checkpoint();
                madeItPastCheckpoint = true;
            }));

            WriteActions(
                new InitializeAction("shardId-0"),
                new ProcessRecordsAction(new DefaultRecord("1", "a", "hello")),
                new CheckpointAction("456")
            {
                Error = "badstuff"
            }
                );

            KclProcess.Create(recordProcessor, _ioHandler).Run();

            Assert.True(madeItPastCheckpoint,
                        "Code after checkpoint should've executed even though checkpointing failed.");
        }
Beispiel #3
0
        public void CrashOnCorruptActionException()
        {
            WriteLines(_input, "gibberish");

            var kclProcess = KclProcess.Create(Substitute.For <IRecordProcessor>(), _ioHandler);
            var ex         = Assert.Throws <MalformedActionException>(() => kclProcess.Run());
        }
Beispiel #4
0
        public void CrashOnInvalidActionException()
        {
            WriteActions(new CheckpointAction("456")
            {
                Error = "badstuff"
            });

            var kclProcess = KclProcess.Create(Substitute.For <IRecordProcessor>(), _ioHandler);
            var ex         = Assert.Throws <MalformedActionException>(() => kclProcess.Run());
        }
Beispiel #5
0
        public void CrashOnRecordProcessorException()
        {
            Action <IRecordProcessor> runTest = rp =>
            {
                _input.Position = 0;

                var kclProcess = KclProcess.Create(rp, new IoHandler(_input, _output, _error));

                try
                {
                    kclProcess.Run();
                    Assert.Fail("Should have seen the ClientException propagate up the call stack.");
                }
                catch (ClientException)
                {
                    // expected
                }
            };

            WriteActions(
                new InitializeAction("shardId-0"),
                new ProcessRecordsAction(new DefaultRecord("1", "a", "hello")),
                new LeaseLostAction()
                );

            var recordProcessor = Substitute.For <IRecordProcessor>();

            Console.Error.WriteLine("Testing Shutdown");
            recordProcessor.Shutdown(Arg.Do <ShutdownInput>(x =>
            {
                throw new ClientException();
            }));
            runTest.Invoke(recordProcessor);

            Console.Error.WriteLine("Testing ProcessRecords");
            recordProcessor.ProcessRecords(Arg.Do <ProcessRecordsInput>(x =>
            {
                throw new ClientException();
            }));
            runTest.Invoke(recordProcessor);

            Console.Error.WriteLine("Testing Initialize");
            recordProcessor.Initialize(Arg.Do <InitializationInput>(x =>
            {
                throw new ClientException();
            }));
            runTest.Invoke(recordProcessor);
        }
Beispiel #6
0
        public void CrashOnCorruptActionException()
        {
            WriteLines(_input, "gibberish");

            var kclProcess = KclProcess.Create(Substitute.For <IRecordProcessor>(), _ioHandler);

            try
            {
                kclProcess.Run();
                Assert.Fail("Should have thrown a MalformedActionException");
            }
            catch (MalformedActionException)
            {
                // all good
            }
        }
Beispiel #7
0
        public void HappyCase()
        {
            WriteActions(
                new InitializeAction("0"),
                new ProcessRecordsAction(new DefaultRecord("456", "cat", "bWVvdw==")),
                new CheckpointAction("456"),
                new ShardEndedAction(),
                new CheckpointAction("456")
                );

            TestRecordProcessor recordProcessor = new TestRecordProcessor
            {
                ProcessFunc    = (input) => input.Checkpointer.Checkpoint(input.Records.Last()),
                ShardEndedFunc = (input) => input.Checkpointer.Checkpoint()
            };

            KclProcess.Create(recordProcessor, _ioHandler).Run();
            List <Action> outputActions = ParseActionsFromOutput();

            dynamic a = outputActions[0];

            Assert.IsTrue(a is StatusAction);
            Assert.IsTrue(a.ResponseFor == InitializeAction.ACTION);


            a = outputActions[1];
            Assert.IsTrue(a is CheckpointAction);
            Assert.IsTrue(a.SequenceNumber == "456" && a.Error == null);


            a = outputActions[2];
            Assert.IsTrue(a is StatusAction);
            Assert.IsTrue(a.ResponseFor == ProcessRecordsAction.ACTION);


            a = outputActions[3];
            Assert.IsTrue(a is CheckpointAction);
            Assert.IsTrue(a.SequenceNumber == null && a.Error == null);


            a = outputActions[4];
            Assert.IsTrue(a is StatusAction);
            Assert.IsTrue(a.ResponseFor == ShardEndedAction.ACTION);
        }
        public void CrashOnInvalidActionException()
        {
            WriteActions(new CheckpointAction("456")
            {
                Error = "badstuff"
            });

            var kclProcess = KclProcess.Create(Substitute.For <IRecordProcessor>(), _ioHandler);

            try
            {
                kclProcess.Run();
                Assert.Fail("Should have thrown a MalformedActionException");
            }
            catch (MalformedActionException)
            {
                // all good
            }
        }
Beispiel #9
0
        public void CrashOnRecordProcessorException()
        {
            Action <IRecordProcessor> runTest = rp =>
            {
                _input.Position = 0;

                var kclProcess = KclProcess.Create(rp, new IoHandler(_input, _output, _error));
                var ex         = Assert.Throws <ClientException>(() => kclProcess.Run());
            };

            WriteActions(
                new InitializeAction("shardId-0"),
                new ProcessRecordsAction(new DefaultRecord("1", "a", "hello")),
                new ShutdownAction(ShutdownReason.ZOMBIE.ToString())
                );

            var recordProcessor = Substitute.For <IRecordProcessor>();

            Console.Error.WriteLine("Testing Shutdown");
            recordProcessor.Shutdown(Arg.Do <ShutdownInput>(x =>
            {
                throw new ClientException();
            }));
            runTest.Invoke(recordProcessor);

            Console.Error.WriteLine("Testing ProcessRecords");
            recordProcessor.ProcessRecords(Arg.Do <ProcessRecordsInput>(x =>
            {
                throw new ClientException();
            }));
            runTest.Invoke(recordProcessor);

            Console.Error.WriteLine("Testing Initialize");
            recordProcessor.Initialize(Arg.Do <InitializationInput>(x =>
            {
                throw new ClientException();
            }));
            runTest.Invoke(recordProcessor);
        }
Beispiel #10
0
        public void RetryHandler()
        {
            WriteActions(
                new InitializeAction("0"),
                new ProcessRecordsAction(new DefaultRecord("456", "cat", "bWVvdw==")),
                new CheckpointAction(null)
            {
                Error = "oh noes"
            },
                new CheckpointAction(null)
            {
                Error = "oh noes"
            },
                new CheckpointAction(null)
            {
                Error = "oh noes"
            },
                new CheckpointAction(null)
            {
                Error = "oh noes"
            },
                new ShardEndedAction(),
                new CheckpointAction(null)
            {
                Error = "oh noes"
            },
                new CheckpointAction(null)
            {
                Error = "oh noes"
            },
                new CheckpointAction(null)
            {
                Error = "oh noes"
            },
                new CheckpointAction(null)
            {
                Error = "oh noes"
            }
                );

            const int           numRetries      = 3;
            TestRecordProcessor recordProcessor = new TestRecordProcessor
            {
                ProcessFunc = (input) => input.Checkpointer.Checkpoint(input.Records.Last(),
                                                                       RetryingCheckpointErrorHandler.Create(numRetries, TimeSpan.Zero)),
                ShardEndedFunc = (input) => input.Checkpointer.Checkpoint(
                    RetryingCheckpointErrorHandler.Create(numRetries, TimeSpan.Zero))
            };

            KclProcess.Create(recordProcessor, _ioHandler).Run();
            List <Action> outputActions = ParseActionsFromOutput();

            Console.Error.WriteLine(String.Join("\n", outputActions.Select(x => x.ToJson()).ToList()));

            int     i = 0;
            dynamic a = outputActions[i++];

            Assert.IsTrue(a is StatusAction, "Action " + (i - 1) + " should be StatusAction");
            Assert.AreEqual(InitializeAction.ACTION, a.ResponseFor);

            for (int j = 0; j <= numRetries; j++)
            {
                a = outputActions[i++];
                Assert.IsTrue(a is CheckpointAction, "Action " + (i - 1) + " should be CheckpointAction");
                Assert.AreEqual("456", a.SequenceNumber);
                Assert.IsNull(a.Error);
            }

            a = outputActions[i++];
            Assert.IsTrue(a is StatusAction, "Action " + (i - 1) + " should be StatusAction");
            Assert.AreEqual(ProcessRecordsAction.ACTION, a.ResponseFor);

            for (int j = 0; j <= numRetries; j++)
            {
                a = outputActions[i++];
                Assert.IsTrue(a is CheckpointAction, "Action " + (i - 1) + " should be CheckpointAction");
                Assert.IsNull(a.SequenceNumber);
                Assert.IsNull(a.Error);
            }

            a = outputActions[i++];
            Assert.IsTrue(a is StatusAction, "Action " + (i - 1) + " should be StatusAction");
            Assert.AreEqual(ShardEndedAction.ACTION, a.ResponseFor);
        }