Skip to content

Commit

Permalink
Renamed OnlineBackupContextBuilder to Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
phughk committed Jun 14, 2018
1 parent b610ffe commit fe21624
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
Expand Up @@ -32,7 +32,7 @@
class OnlineBackupCommand implements AdminCommand
{
private final OutsideWorld outsideWorld;
private final OnlineBackupContextBuilder contextBuilder;
private final OnlineBackupContextFactory contextBuilder;
private final BackupStrategyCoordinatorFactory backupStrategyCoordinatorFactory;
private final BackupSupportingClassesFactory backupSupportingClassesFactory;

Expand All @@ -44,7 +44,7 @@ class OnlineBackupCommand implements AdminCommand
* @param backupSupportingClassesFactory necessary for constructing the strategy for backing up over the causal clustering transaction protocol
* @param backupStrategyCoordinatorFactory class that actually handles the logic of performing a backup
*/
OnlineBackupCommand( OutsideWorld outsideWorld, OnlineBackupContextBuilder contextBuilder,
OnlineBackupCommand( OutsideWorld outsideWorld, OnlineBackupContextFactory contextBuilder,
BackupSupportingClassesFactory backupSupportingClassesFactory,
BackupStrategyCoordinatorFactory backupStrategyCoordinatorFactory )
{
Expand Down
Expand Up @@ -260,7 +260,7 @@ private String argSelectedProtocol()
{
return Optional.ofNullable( selectedBackupProtocol )
.map( SelectedBackupProtocol::getName )
.map( argValue -> format( "--%s=%s", OnlineBackupContextBuilder.ARG_NAME_PROTO_OVERRIDE, argValue ) )
.map( argValue -> format( "--%s=%s", OnlineBackupContextFactory.ARG_NAME_PROTO_OVERRIDE, argValue ) )
.orElse( "" );
}

Expand Down
Expand Up @@ -50,7 +50,7 @@ public OnlineBackupCommandProvider()
@Nonnull
public Arguments allArguments()
{
return OnlineBackupContextBuilder.arguments();
return OnlineBackupContextFactory.arguments();
}

@Override
Expand Down Expand Up @@ -89,7 +89,7 @@ public AdminCommand create( Path homeDir, Path configDir, OutsideWorld outsideWo
LogProvider logProvider = FormattedLogProvider.withDefaultLogLevel( debug ? Level.DEBUG : Level.NONE ).toOutputStream( outsideWorld.outStream() );
Monitors monitors = new Monitors();

OnlineBackupContextBuilder contextBuilder = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory contextBuilder = new OnlineBackupContextFactory( homeDir, configDir );
BackupModule backupModule = new BackupModule( outsideWorld, logProvider, monitors );

BackupSupportingClassesFactoryProvider classesFactoryProvider =
Expand Down
Expand Up @@ -55,7 +55,7 @@
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.pagecache_memory;
import static org.neo4j.kernel.impl.util.Converters.toOptionalHostnamePortFromRawAddress;

class OnlineBackupContextBuilder
class OnlineBackupContextFactory
{
static final String ARG_NAME_BACKUP_DIRECTORY = "backup-dir";
static final String ARG_DESC_BACKUP_DIRECTORY = "Directory to place backup in.";
Expand Down Expand Up @@ -114,7 +114,7 @@ class OnlineBackupContextBuilder
private final Path homeDir;
private final Path configDir;

OnlineBackupContextBuilder( Path homeDir, Path configDir )
OnlineBackupContextFactory( Path homeDir, Path configDir )
{
this.homeDir = homeDir;
this.configDir = configDir;
Expand Down
Expand Up @@ -99,17 +99,6 @@ public static List<String> recordFormats()
private static final String PROP_NAME = "name";
private static final String PROP_RANDOM = "random";

private static void createSomeData( GraphDatabaseService db )
{
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode();
node.setProperty( "name", "Neo" );
db.createNode().createRelationshipTo( node, RelationshipType.withName( "KNOWS" ) );
tx.success();
}
}

@Before
public void resetTasks()
{
Expand Down Expand Up @@ -289,6 +278,17 @@ public void reportsProgress() throws Exception
assertFalse( output.contains( "Finished receiving index snapshots" ) );
}

private static void createSomeData( GraphDatabaseService db )
{
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode();
node.setProperty( "name", "Neo" );
db.createNode().createRelationshipTo( node, RelationshipType.withName( "KNOWS" ) );
tx.success();
}
}

private void repeatedlyPopulateDatabase( GraphDatabaseService db, AtomicBoolean continueFlagReference )
{
while ( continueFlagReference.get() )
Expand Down
Expand Up @@ -77,7 +77,7 @@ public class OnlineBackupCommandTest
@Before
public void setup() throws Exception
{
OnlineBackupContextBuilder contextBuilder = mock( OnlineBackupContextBuilder.class );
OnlineBackupContextFactory contextBuilder = mock( OnlineBackupContextFactory.class );
when( contextBuilder.createContext( any() ) ).thenReturn( onlineBackupContext );

when( outsideWorld.fileSystem() ).thenReturn( fileSystemAbstraction );
Expand Down
Expand Up @@ -59,7 +59,7 @@
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.logical_logs_location;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.pagecache_memory;

public class OnlineBackupContextBuilderTest
public class OnlineBackupContextFactoryTest
{
@Rule
public TestDirectory testDirectory = TestDirectory.testDirectory();
Expand All @@ -85,7 +85,7 @@ public void setUp() throws IOException
@Test
public void unspecifiedHostnameIsEmptyOptional() throws Exception
{
OnlineBackupContextBuilder handler = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory handler = new OnlineBackupContextFactory( homeDir, configDir );
OnlineBackupContext context = handler.createContext( requiredAnd( "--from=:1234" ) );
OnlineBackupRequiredArguments requiredArguments = context.getRequiredArguments();

Expand All @@ -96,7 +96,7 @@ public void unspecifiedHostnameIsEmptyOptional() throws Exception
@Test
public void unspecifiedPortIsEmptyOptional() throws Exception
{
OnlineBackupContextBuilder handler = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory handler = new OnlineBackupContextFactory( homeDir, configDir );
OnlineBackupContext context = handler.createContext( requiredAnd( "--from=abc" ) );
OnlineBackupRequiredArguments requiredArguments = context.getRequiredArguments();

Expand All @@ -107,7 +107,7 @@ public void unspecifiedPortIsEmptyOptional() throws Exception
@Test
public void acceptHostWithTrailingPort() throws Exception
{
OnlineBackupContextBuilder handler = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory handler = new OnlineBackupContextFactory( homeDir, configDir );
OnlineBackupContext context = handler.createContext( requiredAnd( "--from=foo.bar.server:" ) );
OnlineBackupRequiredArguments requiredArguments = context.getRequiredArguments();
assertEquals( "foo.bar.server", requiredArguments.getAddress().getHostname().get() );
Expand All @@ -117,7 +117,7 @@ public void acceptHostWithTrailingPort() throws Exception
@Test
public void acceptPortWithPrecedingEmptyHost() throws Exception
{
OnlineBackupContextBuilder handler = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory handler = new OnlineBackupContextFactory( homeDir, configDir );
OnlineBackupContext context = handler.createContext( requiredAnd( "--from=:1234" ) );
OnlineBackupRequiredArguments requiredArguments = context.getRequiredArguments();
assertFalse( requiredArguments.getAddress().getHostname().isPresent() );
Expand All @@ -127,7 +127,7 @@ public void acceptPortWithPrecedingEmptyHost() throws Exception
@Test
public void acceptBothIfSpecified() throws Exception
{
OnlineBackupContextBuilder handler = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory handler = new OnlineBackupContextFactory( homeDir, configDir );
OnlineBackupContext context = handler.createContext( requiredAnd( "--from=foo.bar.server:1234" ) );
OnlineBackupRequiredArguments requiredArguments = context.getRequiredArguments();
assertEquals( "foo.bar.server", requiredArguments.getAddress().getHostname().get() );
Expand All @@ -139,13 +139,13 @@ public void backupDirectoryArgumentIsMandatory() throws Exception
{
expected.expect( IncorrectUsage.class );
expected.expectMessage( "Missing argument 'backup-dir'" );
new OnlineBackupContextBuilder( homeDir, configDir ).createContext();
new OnlineBackupContextFactory( homeDir, configDir ).createContext();
}

@Test
public void shouldDefaultTimeoutToTwentyMinutes() throws Exception
{
OnlineBackupContextBuilder handler = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory handler = new OnlineBackupContextFactory( homeDir, configDir );
OnlineBackupContext context = handler.createContext( "--backup-dir=/", "--name=mybackup" );
OnlineBackupRequiredArguments requiredArguments = context.getRequiredArguments();

Expand All @@ -155,7 +155,7 @@ public void shouldDefaultTimeoutToTwentyMinutes() throws Exception
@Test
public void shouldInterpretAUnitlessTimeoutAsSeconds() throws Exception
{
OnlineBackupContextBuilder handler = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory handler = new OnlineBackupContextFactory( homeDir, configDir );
OnlineBackupContext context = handler.createContext( "--timeout=10", "--backup-dir=/", "--name=mybackup" );
OnlineBackupRequiredArguments requiredArguments = context.getRequiredArguments();

Expand All @@ -165,7 +165,7 @@ public void shouldInterpretAUnitlessTimeoutAsSeconds() throws Exception
@Test
public void shouldParseATimeoutWithUnits() throws Exception
{
OnlineBackupContextBuilder handler = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory handler = new OnlineBackupContextFactory( homeDir, configDir );
OnlineBackupContext context = handler.createContext( requiredAnd( "--timeout=10h" ) );
OnlineBackupRequiredArguments requiredArguments = context.getRequiredArguments();

Expand All @@ -178,7 +178,7 @@ public void shouldTreatNameArgumentAsMandatory() throws Exception
expected.expect( IncorrectUsage.class );
expected.expectMessage( "Missing argument 'name'" );

OnlineBackupContextBuilder handler = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory handler = new OnlineBackupContextFactory( homeDir, configDir );
handler.createContext( "--backup-dir=/" );
}

Expand All @@ -187,7 +187,7 @@ public void reportDirMustBeAPath() throws Exception
{
expected.expect( IncorrectUsage.class );
expected.expectMessage( "cc-report-dir must be a path" );
OnlineBackupContextBuilder handler = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory handler = new OnlineBackupContextFactory( homeDir, configDir );
handler.createContext( requiredAnd( "--check-consistency", "--cc-report-dir" ) );
}

Expand All @@ -202,7 +202,7 @@ public void errorHandledForNonExistingAdditionalConfigFile() throws Exception
expected.expectCause( hasCause( any( NoSuchFileException.class ) ) );

// expect
OnlineBackupContextBuilder handler = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory handler = new OnlineBackupContextFactory( homeDir, configDir );
handler.createContext( requiredAnd( "--additional-config=" + additionalConf ) );
}

Expand All @@ -217,7 +217,7 @@ public void prioritiseConfigDirOverHomeDir() throws Exception
Files.write( homeDirConfigFile, asList( "causal_clustering.minimum_core_cluster_size_at_startup=5", "causal_clustering.raft_in_queue_max_batch=21" ) );

// when
OnlineBackupContextBuilder handler = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory handler = new OnlineBackupContextFactory( homeDir, configDir );
Config config = handler.createContext( requiredAnd() ).getConfig();

// then
Expand All @@ -236,7 +236,7 @@ public void prioritiseAdditionalOverConfigDir() throws Exception
Files.write( additionalConf, singletonList( "causal_clustering.minimum_core_cluster_size_at_startup=5" ) );

// when
OnlineBackupContextBuilder handler = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory handler = new OnlineBackupContextFactory( homeDir, configDir );
OnlineBackupContext context = handler.createContext( requiredAnd( "--additional-config=" + additionalConf ) );
Config config = context.getConfig();

Expand All @@ -252,7 +252,7 @@ public void mustIgnorePageCacheConfigInConfigFile() throws Exception
Files.write( configFile, singletonList( pagecache_memory.name() + "=42m" ) );

// when
OnlineBackupContextBuilder contextBuilder = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory contextBuilder = new OnlineBackupContextFactory( homeDir, configDir );
OnlineBackupContext context = contextBuilder.createContext( requiredAnd() );

// then
Expand All @@ -267,7 +267,7 @@ public void mustIgnorePageCacheConfigInAdditionalConfigFile() throws Exception
Files.write( additionalConf, singletonList( pagecache_memory.name() + "=42m" ) );

// when
OnlineBackupContextBuilder builder = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory builder = new OnlineBackupContextFactory( homeDir, configDir );
OnlineBackupContext context = builder.createContext( requiredAnd( "--additional-config=" + additionalConf ) );

// then
Expand All @@ -278,7 +278,7 @@ public void mustIgnorePageCacheConfigInAdditionalConfigFile() throws Exception
public void mustRespectPageCacheConfigFromCommandLineArguments() throws Exception
{
// when
OnlineBackupContextBuilder builder = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory builder = new OnlineBackupContextFactory( homeDir, configDir );
OnlineBackupContext context = builder.createContext( requiredAnd( "--pagecache=42m" ) );

// then
Expand All @@ -293,7 +293,7 @@ public void logsMustBePlacedInTargetBackupDirectory() throws Exception
Path backupDir = homeDir.resolve( "poke" );
Path backupPath = backupDir.resolve( name );
Files.createDirectories( backupDir );
OnlineBackupContextBuilder builder = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory builder = new OnlineBackupContextFactory( homeDir, configDir );
OnlineBackupContext context = builder.createContext( "--backup-dir=" + backupDir, "--name=" + name );
assertThat( context.getConfig().get( logical_logs_location ).getAbsolutePath(), is( backupPath.toString() ) );
}
Expand All @@ -302,7 +302,7 @@ public void logsMustBePlacedInTargetBackupDirectory() throws Exception
public void defaultProtocolIsAny() throws CommandFailed, IncorrectUsage
{
// given
OnlineBackupContextBuilder builder = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory builder = new OnlineBackupContextFactory( homeDir, configDir );

// when context resolved without proto override value
OnlineBackupContext context = builder.createContext( requiredAnd() );
Expand All @@ -321,7 +321,7 @@ public void overrideWithLegacy() throws CommandFailed, IncorrectUsage
for ( int useCase = 0; useCase < input.size(); useCase++ )
{
// given
OnlineBackupContextBuilder builder = new OnlineBackupContextBuilder( homeDir, configDir );
OnlineBackupContextFactory builder = new OnlineBackupContextFactory( homeDir, configDir );

// when
OnlineBackupContext context = builder.createContext( requiredAnd( "--protocol=" + input.get( useCase ) ) );
Expand Down

0 comments on commit fe21624

Please sign in to comment.