Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add progress output to
neo4j-admin dump
.
- Loading branch information
Showing
7 changed files
with
263 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
community/dbms/src/main/java/org/neo4j/dbms/archive/ProgressPrinter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright (c) 2002-2019 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.dbms.archive; | ||
|
||
import java.io.PrintStream; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import org.neo4j.io.ByteUnit; | ||
|
||
class ProgressPrinter | ||
{ | ||
private final AtomicBoolean printUpdate; | ||
private final PrintStream output; | ||
long maxBytes; | ||
long maxFiles; | ||
long currentBytes; | ||
long currentFiles; | ||
boolean done; | ||
|
||
ProgressPrinter( PrintStream output ) | ||
{ | ||
this.output = output; | ||
printUpdate = new AtomicBoolean(); | ||
} | ||
|
||
void printOnNextUpdate() | ||
{ | ||
printUpdate.set( true ); | ||
} | ||
|
||
void reset() | ||
{ | ||
maxBytes = 0; | ||
maxFiles = 0; | ||
currentBytes = 0; | ||
currentFiles = 0; | ||
} | ||
|
||
void beginFile() | ||
{ | ||
currentFiles++; | ||
} | ||
|
||
void addBytes( long n ) | ||
{ | ||
currentBytes += n; | ||
if ( printUpdate.get() ) | ||
{ | ||
printProgress(); | ||
printUpdate.set( false ); | ||
} | ||
} | ||
|
||
void endFile() | ||
{ | ||
printProgress(); | ||
} | ||
|
||
void done() | ||
{ | ||
done = true; | ||
} | ||
|
||
void printProgress() | ||
{ | ||
if ( output != null ) | ||
{ | ||
if ( done ) | ||
{ | ||
output.println( "\rDone: " + currentFiles + " files, " + ByteUnit.bytesToString( currentBytes ) + " processed." ); | ||
} | ||
else | ||
{ | ||
double progress = (currentBytes / (double) maxBytes) * 100; | ||
output.print( "\rFiles: " + currentFiles + '/' + maxFiles + ", data: " + String.format( "%4.1f%%", progress )); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
community/dbms/src/test/java/org/neo4j/dbms/archive/ProgressPrinterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2002-2019 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.dbms.archive; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class ProgressPrinterTest | ||
{ | ||
@Test | ||
void progressOutput() | ||
{ | ||
ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
PrintStream printStream = new PrintStream( bout ); | ||
ProgressPrinter progressPrinter = new ProgressPrinter( printStream ); | ||
progressPrinter.maxBytes = 1000; | ||
progressPrinter.maxFiles = 10; | ||
|
||
progressPrinter.beginFile(); | ||
progressPrinter.addBytes( 5 ); | ||
progressPrinter.endFile(); | ||
progressPrinter.beginFile(); | ||
progressPrinter.addBytes( 50 ); | ||
progressPrinter.addBytes( 50 ); | ||
progressPrinter.printOnNextUpdate(); | ||
progressPrinter.addBytes( 100 ); | ||
progressPrinter.endFile(); | ||
progressPrinter.beginFile(); | ||
progressPrinter.printOnNextUpdate(); | ||
progressPrinter.addBytes( 100 ); | ||
progressPrinter.endFile(); | ||
progressPrinter.done(); | ||
progressPrinter.printProgress(); | ||
|
||
printStream.flush(); | ||
String output = bout.toString(); | ||
assertEquals( output, | ||
"\rFiles: 1/10, data: 0.5%" + | ||
"\rFiles: 2/10, data: 20.5%" + | ||
"\rFiles: 2/10, data: 20.5%" + | ||
"\rFiles: 3/10, data: 30.5%" + | ||
"\rFiles: 3/10, data: 30.5%" + | ||
"\rDone: 3 files, 305B processed." + | ||
System.lineSeparator() | ||
); | ||
} | ||
} |