Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldWrapIOExceptionsCarefullyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldWrapIOExceptionsCarefullyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage()
        {
            doThrow(new IOException("the-message")).when(_dumper).dump(any(), any(), any(), any(), any());
            CommandFailed commandFailed = assertThrows(typeof(CommandFailed), () => execute("foo.db"));

            assertEquals("unable to dump database: IOException: the-message", commandFailed.Message);
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldGiveAClearMessageIfTheArchivesParentDoesntExist() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldGiveAClearMessageIfTheArchivesParentDoesntExist()
        {
            doThrow(new NoSuchFileException(_archive.Parent.ToString())).when(_dumper).dump(any(), any(), any(), any(), any());
            CommandFailed commandFailed = assertThrows(typeof(CommandFailed), () => execute("foo.db"));

            assertEquals("unable to dump database: NoSuchFileException: " + _archive.Parent, commandFailed.Message);
        }
Example #3
0
        /// <summary>
        /// Iterate over all the provided strategies trying to perform a successful backup.
        /// Will also do consistency checks if specified in <seealso cref="OnlineBackupContext"/>
        /// </summary>
        /// <param name="onlineBackupContext"> filesystem, command arguments and configuration </param>
        /// <exception cref="CommandFailed"> when backup failed or there were issues with consistency checks </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void performBackup(OnlineBackupContext onlineBackupContext) throws org.neo4j.commandline.admin.CommandFailed
        public virtual void PerformBackup(OnlineBackupContext onlineBackupContext)
        {
            // Convenience
            OnlineBackupRequiredArguments requiredArgs = onlineBackupContext.RequiredArguments;
            Path             destination      = onlineBackupContext.ResolvedLocationFromName;
            ConsistencyFlags consistencyFlags = onlineBackupContext.ConsistencyFlags;

            Fallible <BackupStrategyOutcome> throwableWithState = null;
            IList <Exception> causesOfFailure = new List <Exception>();

            foreach (BackupStrategyWrapper backupStrategy in _strategies)
            {
                throwableWithState = backupStrategy.DoBackup(onlineBackupContext);
                if (throwableWithState.State == BackupStrategyOutcome.Success)
                {
                    break;
                }
                if (throwableWithState.State == BackupStrategyOutcome.CorrectStrategyFailed)
                {
                    throw CommandFailedWithCause(throwableWithState).get();
                }
                throwableWithState.Cause.ifPresent(causesOfFailure.add);
            }
            if (throwableWithState == null || !BackupStrategyOutcome.Success.Equals(throwableWithState.State))
            {
                CommandFailed commandFailed = new CommandFailed("Failed to run a backup using the available strategies.");
                causesOfFailure.ForEach(commandFailed.addSuppressed);
                throw commandFailed;
            }
            if (requiredArgs.DoConsistencyCheck)
            {
                PerformConsistencyCheck(onlineBackupContext.Config, requiredArgs, consistencyFlags, DatabaseLayout.of(destination.toFile()));
            }
        }
Example #4
0
        private void OnCommandFailed(
            CommandFailed commandFailed,
            IJupyterMessageSender jupyterMessageSender)
        {
            var traceBack = new List <string>();

            switch (commandFailed.Exception)
            {
            case CodeSubmissionCompilationErrorException _:
                traceBack.Add(commandFailed.Message);
                break;

            default:
                traceBack.Add("Unhandled Exception");
                traceBack.Add(commandFailed.Message);
                traceBack.AddRange(commandFailed.Exception?.StackTrace?.Split(new[] { Environment.NewLine }, StringSplitOptions.None) ?? Enumerable.Empty <string>());
                break;
            }

            var errorContent = new Error(
                eName: "Unhandled Exception",
                eValue: commandFailed.Message,
                traceback: traceBack
                );

            // send on iopub
            jupyterMessageSender.Send(errorContent);


            //  reply Error
            var executeReplyPayload = new ExecuteReplyError(errorContent, executionCount: _executionCount);

            // send to server
            jupyterMessageSender.Send(executeReplyPayload);
        }
Example #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldGiveAClearErrorIfTheArchiveAlreadyExists() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldGiveAClearErrorIfTheArchiveAlreadyExists()
        {
            doThrow(new FileAlreadyExistsException("the-archive-path")).when(_dumper).dump(any(), any(), any(), any(), any());
            CommandFailed commandFailed = assertThrows(typeof(CommandFailed), () => execute("foo.db"));

            assertEquals("archive already exists: the-archive-path", commandFailed.Message);
        }
Example #6
0
        public void When_a_cancel_has_been_not_signaled_then_IsCanceled_returns_false()
        {
            var failed = new CommandFailed(new ScheduledCommand <NonEventSourcedCommandTarget>(new TestCommand(), Any.Guid()));

            failed.IsCanceled
            .Should()
            .BeFalse();
        }
Example #7
0
        public void When_a_retry_is_not_pending_then_WillBeRetried_returns_false()
        {
            var failed = new CommandFailed(new ScheduledCommand <NonEventSourcedCommandTarget>(new TestCommand(), Any.Guid()));

            failed.WillBeRetried
            .Should()
            .BeFalse();
        }
        public void When_a_cancel_has_been_not_signaled_then_IsCanceled_returns_false()
        {
            var failed = new CommandFailed(new ScheduledCommand<NonEventSourcedCommandTarget>(new TestCommand(), Any.Guid()));

            failed.IsCanceled
                  .Should()
                  .BeFalse();
        }
Example #9
0
        public async Task HandleScheduledCommandException(CommandTarget target, CommandFailed <TestCommand> failed)
        {
            target.CommandsFailed.Add(failed);

            target.OnHandleScheduledCommandError
            .IfNotNull()
            .ThenDo(enact => enact(target, failed));
        }
        public void When_a_retry_is_not_pending_then_WillBeRetried_returns_false()
        {
            var failed = new CommandFailed(new ScheduledCommand<NonEventSourcedCommandTarget>(new TestCommand(), Any.Guid()));

            failed.WillBeRetried
                  .Should()
                  .BeFalse();
        }
 public async Task HandleScheduledCommandException(
     CommandSchedulerTestAggregate aggregate,
     CommandFailed <CommandThatSchedulesAnotherCommand> command)
 {
     aggregate.RecordEvent(new CommandFailed
     {
         Command = command.Command
     });
 }
        public void NumberOfPreviousAttempts_returns_the_value_set_on_the_scheduled_command()
        {
            var failed = new CommandFailed(new ScheduledCommand<NonEventSourcedCommandTarget>(new TestCommand(), Any.Guid())
            {
                NumberOfPreviousAttempts = 8
            });

            failed.NumberOfPreviousAttempts.Should().Be(8);
        }
Example #13
0
        public void NumberOfPreviousAttempts_returns_the_value_set_on_the_scheduled_command()
        {
            var failed = new CommandFailed(new ScheduledCommand <NonEventSourcedCommandTarget>(new TestCommand(), Any.Guid())
            {
                NumberOfPreviousAttempts = 8
            });

            failed.NumberOfPreviousAttempts.Should().Be(8);
        }
        public void When_a_retry_is_pending_then_WillBeRetried_returns_true()
        {
            var failed = new CommandFailed(new ScheduledCommand<CommandTarget>(new TestCommand(), Any.Guid()));

            failed.Retry();

            failed.WillBeRetried
                  .Should()
                  .BeTrue();
        }
Example #15
0
        public void When_a_retry_is_pending_then_WillBeRetried_returns_true()
        {
            var failed = new CommandFailed(new ScheduledCommand <CommandTarget>(new TestCommand(), Any.Guid()));

            failed.Retry();

            failed.WillBeRetried
            .Should()
            .BeTrue();
        }
Example #16
0
        public void When_a_cancel_has_been_signaled_then_IsCanceled_returns_true()
        {
            var failed = new CommandFailed(new ScheduledCommand <CommandTarget>(new TestCommand(), Any.Guid()));

            failed.Cancel();

            failed.IsCanceled
            .Should()
            .BeTrue();
        }
        public void When_a_cancel_has_been_signaled_then_IsCanceled_returns_true()
        {
            var failed = new CommandFailed(new ScheduledCommand<CommandTarget>(new TestCommand(), Any.Guid()));

            failed.Cancel();

            failed.IsCanceled
                  .Should()
                  .BeTrue();
        }
Example #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void errorOnInvalidPid() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ErrorOnInvalidPid()
        {
            string[] args = new string[] { "--pid=a", "all" };
            using (RealOutsideWorld outsideWorld = new RealOutsideWorld())
            {
                DiagnosticsReportCommand diagnosticsReportCommand = new DiagnosticsReportCommand(_homeDir, _configDir, outsideWorld);
                CommandFailed            commandFailed            = assertThrows(typeof(CommandFailed), () => diagnosticsReportCommand.execute(args));
                assertEquals("Unable to parse --pid", commandFailed.Message);
            }
        }
Example #19
0
        public void Fail(
            Exception exception = null,
            string message      = null)
        {
            var failed = new CommandFailed(exception, Command, message);

            Publish(failed);

            _events.OnCompleted();
            IsComplete = true;
        }
Example #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void exitIfConfigFileIsMissing() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ExitIfConfigFileIsMissing()
        {
            Files.delete(_configFile);
            string[] args = new string[] { "--list" };
            using (RealOutsideWorld outsideWorld = new RealOutsideWorld())
            {
                DiagnosticsReportCommand diagnosticsReportCommand = new DiagnosticsReportCommand(_homeDir, _configDir, outsideWorld);

                CommandFailed commandFailed = assertThrows(typeof(CommandFailed), () => diagnosticsReportCommand.execute(args));
                assertThat(commandFailed.Message, containsString("Unable to find config file, tried: "));
            }
        }
        public void FailTwo()
        {
            var context    = Substitute.For <IUpstreamContext>();
            var msg        = new CommandFailed(new DispatchCommand(new FakeCommand(), 1), new Exception());
            var dispatcher = new RetryingHandler(3);

            dispatcher.HandleUpstream(context, msg);

            context.Received().SendUpstream(Arg.Any <CommandFailed>());
            context.Received().SendDownstream(Arg.Any <DispatchCommand>());
            context.DidNotReceive().SendUpstream(Arg.Any <CommandAborted>());
        }
Example #22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void databaseThatRequireRecoveryIsNotDumpable() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void DatabaseThatRequireRecoveryIsNotDumpable()
        {
            File logFile = new File(_databaseDirectory.toFile(), TransactionLogFiles.DEFAULT_NAME + ".0");

            using (StreamWriter fileWriter = new StreamWriter(logFile))
            {
                fileWriter.Write("brb");
            }
            CommandFailed commandFailed = assertThrows(typeof(CommandFailed), () => execute("foo.db"));

            assertThat(commandFailed.Message, startsWith("Active logical log detected, this might be a source of inconsistencies."));
        }
 public ScheduledCommandException(CommandFailed failure)
     : base(failure.Exception
                   .IfNotNull()
                   .Then(e => e.Message)
                   .Else(() => "Scheduled command failed"),
            failure.Exception)
 {
     if (failure == null)
     {
         throw new ArgumentNullException(nameof(failure));
     }
     Failure = failure;
 }
Example #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldRespectTheStoreLock() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldRespectTheStoreLock()
        {
            Path        databaseDirectory = _homeDir.resolve("data/databases/foo.db");
            StoreLayout storeLayout       = DatabaseLayout.of(databaseDirectory.toFile()).StoreLayout;

            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), StoreLocker storeLocker = new StoreLocker(fileSystem, storeLayout))
            {
                storeLocker.CheckLock();

                CommandFailed commandFailed = assertThrows(typeof(CommandFailed), () => execute("foo.db"));
                assertEquals("the database is in use -- stop Neo4j and try again", commandFailed.Message);
            }
        }
Example #25
0
 public async Task HandleScheduledCommandException(Order order, CommandFailed <ChargeCreditCard> command)
 {
     if (command.NumberOfPreviousAttempts < 3)
     {
         command.Retry(after: command.Command.ChargeRetryPeriod);
     }
     else
     {
         order.RecordEvent(new Cancelled
         {
             Reason = "Final credit card charge attempt failed."
         });
     }
 }
Example #26
0
            public async Task HandleScheduledCommandException(Order order, CommandFailed <Ship> command)
            {
                if (command.Exception is CommandValidationException)
                {
                    if (order.IsCancelled)
                    {
                        order.RecordEvent(new ShipmentCancelled());
                    }

                    if (order.IsShipped)
                    {
                        command.Cancel();
                    }
                }
            }
Example #27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) void shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock()
        {
            StoreLayout storeLayout = DatabaseLayout.of(_databaseDirectory.toFile()).StoreLayout;

            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), StoreLocker storeLocker = new StoreLocker(fileSystem, storeLayout))
            {
                storeLocker.CheckLock();

                using (System.IDisposable ignored = withPermissions(storeLayout.StoreLockFile().toPath(), emptySet()))
                {
                    CommandFailed commandFailed = assertThrows(typeof(CommandFailed), () => execute("foo.db"));
                    assertEquals(commandFailed.Message, "you do not have permission to dump the database -- is Neo4j running as a different user?");
                }
            }
        }
Example #28
0
        private void OnCommandFailed(
            CommandFailed commandFailed,
            IJupyterMessageSender jupyterMessageSender)
        {
            var errorContent = new Error(
                eName: "Unhandled Exception",
                eValue: commandFailed.Message
                );


            //  reply Error
            var executeReplyPayload = new ExecuteReplyError(errorContent, executionCount: _executionCount);

            // send to server
            jupyterMessageSender.Send(executeReplyPayload);
        }
        private void OnCommandFailed(
            CommandFailed commandFailed,
            IJupyterMessageSender jupyterMessageSender)
        {
            var traceBack = new List <string>();
            var ename     = "Unhandled exception";
            var emsg      = commandFailed.Message;

            switch (commandFailed.Exception)
            {
            case CodeSubmissionCompilationErrorException _:
                // The diagnostics have already been reported
                ename = "Cell not executed";
                emsg  = "compilation error";
                break;

            case null:

                traceBack.Add(commandFailed.Message);
                break;

            default:
                var exception = commandFailed.Exception;

                traceBack.Add(exception.ToString());

                traceBack.AddRange(
                    exception.StackTrace.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));

                break;
            }

            var errorContent = new Error(
                eName: ename,
                eValue: emsg,
                traceback: traceBack
                );

            // send on iopub
            jupyterMessageSender.Send(errorContent);

            //  reply Error
            var executeReplyPayload = new ExecuteReplyError(errorContent, executionCount: _executionCount);

            // send to server
            jupyterMessageSender.Send(executeReplyPayload);
        }
Example #30
0
        private void OnCommandFailed(
            CommandFailed commandFailed,
            IJupyterMessageSender jupyterMessageSender)
        {
            var traceBack = new List <string>();

            switch (commandFailed.Exception)
            {
            case CodeSubmissionCompilationErrorException _:
                traceBack.Add(commandFailed.Message);
                break;

            case null:

                traceBack.Add(commandFailed.Message);
                break;

            default:
                var exception = commandFailed.Exception;

                traceBack.Add(
                    $"{exception.GetType().FullName}: {exception.Message}");

                traceBack.AddRange(
                    exception.StackTrace.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));

                break;
            }

            var errorContent = new Error(
                eName: "Unhandled exception",
                eValue: commandFailed.Message,
                traceback: traceBack
                );

            // send on iopub
            jupyterMessageSender.Send(errorContent);


            //  reply Error
            var executeReplyPayload = new ExecuteReplyError(errorContent, executionCount: _executionCount);

            // send to server
            jupyterMessageSender.Send(executeReplyPayload);
        }
Example #31
0
 private static string Description(
     IScheduledCommand <TAggregate> scheduledCommand,
     CommandFailed failure)
 {
     return(new
     {
         Name = scheduledCommand.Command.CommandName,
         failure.IsCanceled,
         failure.NumberOfPreviousAttempts,
         failure.RetryAfter,
         failure.Exception,
         DueTime = scheduledCommand.DueTime
                   .IfNotNull()
                   .Then(t => t.ToString("O"))
                   .Else(() => "[null]"),
         Clocks = Domain.Clock.Current.ToString(),
         scheduledCommand.AggregateId,
         scheduledCommand.ETag
     }.ToString());
 }
Example #32
0
        private void OnCommandFailed(CommandFailed commandFailed)
        {
            if (!InFlightRequests.TryRemove(commandFailed.GetRootCommand(), out var openRequest))
            {
                return;
            }

            var errorContent = new Error(
                eName: "Unhandled Exception",
                eValue: commandFailed.Message
                );

            if (!openRequest.Request.Silent)
            {
                // send on io
                var error = Message.Create(
                    errorContent,
                    openRequest.Context.Request.Header);
                openRequest.Context.IoPubChannel.Send(error);

                // send on stderr
                var stdErr = new StdErrStream(errorContent.EValue);
                var stream = Message.Create(
                    stdErr,
                    openRequest.Context.Request.Header);
                openRequest.Context.IoPubChannel.Send(stream);
            }

            //  reply Error
            var executeReplyPayload = new ExecuteReplyError(errorContent, executionCount: openRequest.ExecutionCount);

            // send to server
            var executeReply = Message.CreateResponse(
                executeReplyPayload,
                openRequest.Context.Request);

            openRequest.Context.ServerChannel.Send(executeReply);

            openRequest.Context.RequestHandlerStatus.SetAsIdle();
            openRequest.Dispose();
        }
Example #33
0
        private void OnCommandFailed(
            CommandFailed commandFailed,
            Message request,
            IMessageSender serverChannel,
            IMessageSender ioPubChannel)
        {
            var errorContent = new Error(
                eName: "Unhandled Exception",
                eValue: commandFailed.Message
                );

            var isSilent = ((ExecuteRequest)request.Content).Silent;

            if (!isSilent)
            {
                // send on io
                var error = Message.Create(
                    errorContent,
                    request.Header);

                ioPubChannel.Send(error);

                // send on stderr
                var stdErr = Stream.StdErr(errorContent.EValue);
                var stream = Message.Create(
                    stdErr,
                    request.Header);

                ioPubChannel.Send(stream);
            }

            //  reply Error
            var executeReplyPayload = new ExecuteReplyError(errorContent, executionCount: _executionCount);

            // send to server
            var executeReply = Message.CreateResponse(
                executeReplyPayload,
                request);

            serverChannel.Send(executeReply);
        }
Example #34
0
        private void _bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            _watch.Stop();

            if (e.Cancelled)
            {
                _status = CommandStatus.Aborted;
                CommandAborted?.Raise(this, new EventArgs());
            }
            else
            {
                if (e.Error != null)
                {
                    _status = CommandStatus.Error;
                    CommandFailed?.Raise(this, new ErrorEventArgs(e.Error));
                }
                else
                {
                    _status = CommandStatus.Success;
                    CommandSuccess?.Raise(this, new EventArgs());
                }
            }
        }
Example #35
0
 /// <summary>
 /// TBD
 /// </summary>
 protected Command()
 {
     FailureMessage = new CommandFailed(this);
 }
 public async Task HandleScheduledCommandException(CustomerAccount aggregate, CommandFailed <SendMarketingEmail> command)
 {
 }
Example #37
0
 public void Failed(CommandFailed callback)
 {
     ((ICanProcessCommandProcess)Proxy).AddFailed(callback);
 }