예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTrackOffsetAfterRewind() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTrackOffsetAfterRewind()
        {
            // given
            Stream           actual           = mock(typeof(Stream));
            ProgressListener progressListener = mock(typeof(ProgressListener));

            ProgressTrackingOutputStream.Progress progress = new ProgressTrackingOutputStream.Progress(progressListener, 0);
            using (ProgressTrackingOutputStream @out = new ProgressTrackingOutputStream(actual, progress))
            {
                @out.WriteByte(new sbyte[20]);

                // when
                progress.RewindTo(15);                           // i.e. the next 5 bytes we don't track
                @out.WriteByte(new sbyte[3]);                    // now there should be 2 untracked bytes left
                @out.WriteByte(new sbyte[9]);                    // this one should report 7
            }
            progress.Done();

            // then
            InOrder inOrder = inOrder(progressListener);

            inOrder.verify(progressListener).add(20);
            inOrder.verify(progressListener).add(7);
            inOrder.verify(progressListener).done();
            verifyNoMoreInteractions(progressListener);
        }
예제 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void doStatusPolling(boolean verbose, String consoleURL, String bearerToken) throws java.io.IOException, InterruptedException, org.neo4j.commandline.admin.CommandFailed
        private void DoStatusPolling(bool verbose, string consoleURL, string bearerToken)
        {
            _outsideWorld.stdOutLine("We have received your export and it is currently being loaded into your cloud instance.");
            _outsideWorld.stdOutLine("You can wait here, or abort this command and head over to the console to be notified of when your database is running.");
            string bearerTokenHeader = "Bearer " + bearerToken;

            ProgressTrackingOutputStream.Progress statusProgress = new ProgressTrackingOutputStream.Progress(_progressListenerFactory.create("Import status", 3L), 0);
            bool firstRunning         = true;
            long importStartedTimeout = DateTimeHelper.CurrentUnixTimeMillis() + 90 * 1000;               // timeout to switch from first running to loading = 1.5 minute

            while (!statusProgress.Done)
            {
                string status = GetDatabaseStatus(verbose, SafeUrl(consoleURL + "/import/status"), bearerTokenHeader);
                switch (status)
                {
                case "running":
                    // It could happen that the very first call of this method is so fast, that the database is still in state
                    // "running". So we need to check if this is the case and ignore the result in that case and only
                    // take this result as valid, once the status loading or restoring was seen before.
                    if (!firstRunning)
                    {
                        statusProgress.RewindTo(0);
                        statusProgress.Add(3);
                        statusProgress.Done();
                    }
                    else
                    {
                        bool passedStartImportTimeout = DateTimeHelper.CurrentUnixTimeMillis() > importStartedTimeout;
                        if (passedStartImportTimeout)
                        {
                            throw new CommandFailed("We're sorry, it couldn't be detected that the import was started, " + "please check the console for further details.");
                        }
                    }
                    break;

                case "loading":
                    firstRunning = false;
                    statusProgress.RewindTo(0);
                    statusProgress.Add(1);
                    break;

                case "restoring":
                    firstRunning = false;
                    statusProgress.RewindTo(0);
                    statusProgress.Add(2);
                    break;

                case "loading failed":
                    throw new CommandFailed("We're sorry, something has gone wrong. We did not recognize the file you uploaded as a valid Neo4j dump file. " + "Please check the file and try again. If you have received this error after confirming the type of file being uploaded," + "please open a support case.");

                default:
                    throw new CommandFailed(string.Format("We're sorry, something has failed during the loading of your database. " + "Please try again and if this problem persists, please open up a support case. Database status: {0}", status));
                }
                _sleeper.sleep(2000);
            }
            _outsideWorld.stdOutLine("Your data was successfully pushed to cloud and is now running.");
        }
예제 #3
0
        /// <summary>
        /// Do the actual transfer of the source (a Neo4j database dump) to the target.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void copy(boolean verbose, String consoleURL, java.nio.file.Path source, String bearerToken) throws org.neo4j.commandline.admin.CommandFailed
        public override void Copy(bool verbose, string consoleURL, Path source, string bearerToken)
        {
            try
            {
                string bearerTokenHeader = "Bearer " + bearerToken;
                long   crc32Sum          = CalculateCrc32HashOfFile(source);
                URL    signedURL         = InitiateCopy(verbose, SafeUrl(consoleURL + "/import"), crc32Sum, bearerTokenHeader);
                URL    uploadLocation    = InitiateResumableUpload(verbose, signedURL);
                long   sourceLength      = _outsideWorld.fileSystem().getFileSize(source.toFile());

                // Enter the resume:able upload loop
                long position            = 0;
                int  retries             = 0;
                ThreadLocalRandom random = ThreadLocalRandom.current();
                ProgressTrackingOutputStream.Progress uploadProgress = new ProgressTrackingOutputStream.Progress(_progressListenerFactory.create("Upload", sourceLength), position);
                while (!ResumeUpload(verbose, source, sourceLength, position, uploadLocation, uploadProgress))
                {
                    position = GetResumablePosition(verbose, sourceLength, uploadLocation);
                    if (position == POSITION_UPLOAD_COMPLETED)
                    {
                        // This is somewhat unexpected, we didn't get an OK from the upload, but when we asked about how far the upload
                        // got it responded that it was fully uploaded. I'd guess we're fine here.
                        break;
                    }

                    // Truncated exponential backoff
                    if (retries > 50)
                    {
                        throw new CommandFailed("Upload failed after numerous attempts. The upload can be resumed with this command: TODO");
                    }
                    long backoffFromRetryCount = SECONDS.toMillis(1 << retries++) + random.Next(1_000);
                    _sleeper.sleep(min(backoffFromRetryCount, _maximumRetryBackoff));
                }
                uploadProgress.Done();

                TriggerImportProtocol(verbose, SafeUrl(consoleURL + "/import/upload-complete"), crc32Sum, bearerTokenHeader);

                DoStatusPolling(verbose, consoleURL, bearerToken);
            }
            catch (Exception e) when(e is InterruptedException || e is IOException)
            {
                throw new CommandFailed(e.Message, e);
            }
        }
예제 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTrackSingleByteWrites() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTrackSingleByteWrites()
        {
            // given
            Stream           actual           = mock(typeof(Stream));
            ProgressListener progressListener = mock(typeof(ProgressListener));

            ProgressTrackingOutputStream.Progress progress = new ProgressTrackingOutputStream.Progress(progressListener, 0);
            using (ProgressTrackingOutputStream @out = new ProgressTrackingOutputStream(actual, progress))
            {
                // when
                @out.WriteByte(10);
            }
            progress.Done();

            // then
            verify(progressListener).add(1);
            verify(progressListener).done();
            verifyNoMoreInteractions(progressListener);
        }
예제 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTrackOffsetByteArrayWrites() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTrackOffsetByteArrayWrites()
        {
            // given
            Stream           actual           = mock(typeof(Stream));
            ProgressListener progressListener = mock(typeof(ProgressListener));

            ProgressTrackingOutputStream.Progress progress = new ProgressTrackingOutputStream.Progress(progressListener, 0);
            int length = 5;

            using (ProgressTrackingOutputStream @out = new ProgressTrackingOutputStream(actual, progress))
            {
                // when
                @out.Write(new sbyte[length * 2], 2, length);
            }
            progress.Done();

            // then
            verify(progressListener).add(length);
            verify(progressListener).done();
            verifyNoMoreInteractions(progressListener);
        }