Skip to content

Commit

Permalink
Remove some functionality from Powershell scripts to make it easier t…
Browse files Browse the repository at this point in the history
…o switch to database-by-name
  • Loading branch information
benbc committed Feb 22, 2016
1 parent 6e28dc9 commit ff54181
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 94 deletions.
2 changes: 0 additions & 2 deletions community/server/src/docs/ops/powershell.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ Start-Neo4jServer -Console
Initialize-Neo4jServer `
-ListenOnIPAddress 127.0.0.1 `
-HTTPPort 7475 `
-ClearExistingDatabase `
-OnlineBackupServer '127.0.0.1:6363' `
-PassThru |
Initialize-Neo4jHACluster `
Expand All @@ -208,7 +207,6 @@ Start-Neo4jServer -Console
Initialize-Neo4jServer `
-ListenOnIPAddress 127.0.0.1 `
-HTTPPort 7476 `
-ClearExistingDatabase `
-OnlineBackupServer '127.0.0.1:6364' `
-PassThru |
Initialize-Neo4jHACluster `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ Use 0.0.0.0 to use any network interface
Disable the Neo4j authentication. By default authentication is enabled
This is only applicable to Neo4j 2.2 and above.
.PARAMETER ClearExistingDatabase
Delete the existing graph data files
.PARAMETER DisableOnlineBackup
Disable the online backup service
This only applicable to Enterprise Neo4j Servers and will raise an error on Community servers
Expand Down Expand Up @@ -128,9 +125,6 @@ Function Initialize-Neo4jServer
,[Parameter(Mandatory=$false)]
[switch]$DisableAuthentication

,[Parameter(Mandatory=$false)]
[switch]$ClearExistingDatabase

,[Parameter(Mandatory=$false)]
[switch]$DisableOnlineBackup

Expand Down Expand Up @@ -186,13 +180,6 @@ Function Initialize-Neo4jServer
ForEach-Object -Process { $_.Neo4jHome = $thisServer.Home; if ($_.Value -ne '') { Write-Output $_} } | `
Set-Neo4jSetting

if ($ClearExistingDatabase)
{
$dbSetting = ($thisServer | Get-Neo4jSetting | ? { (($_.ConfigurationFile -eq 'neo4j.conf') -and ($_.Name -eq 'org.neo4j.server.database.location')) })
$dbPath = Join-Path -Path $thisServer.Home -ChildPath $dbSetting.Value
if (Test-Path -Path $dbPath) { Remove-Item -Path $dbPath -Recurse -Force }
}

if ($PassThru) { Write-Output $thisServer } else { Write-Output $settings }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,32 +114,11 @@ Function Start-Neo4jImport
return
}

# Get the path to the graph data directory
$graphPath = ''
$setting = ($thisServer | Get-Neo4jSetting -ConfigurationFile 'neo4j.conf' -Name 'org.neo4j.server.database.location')
if ($setting -ne $null) { $graphPath = "$($thisServer.Home)\$($setting.Value.Replace('/','\'))" }

$ShellArgs = $JavaCMD.args
# Add unbounded command line arguments. Check if --into was specified
$intoParam = $false
# Add unbounded command line arguments.
if ($OtherArgs -ne $null)
{
$ShellArgs += $OtherArgs
$OtherArgs | ForEach-Object -Process `
{
$intoParam = $intoParam -or ($_.ToUpper() -eq '--INTO')
}
}
# Insert the --into param if it's not already specified
if (-not $intoParam)
{
if ([string]$graphPath -eq '')
{
Write-Error 'Unable to determine the graph directory from the configuration settings'
return
}

$ShellArgs += @('--into',$graphPath)
}

$result = (Start-Process -FilePath $JavaCMD.java -ArgumentList $ShellArgs -Wait:$Wait -NoNewWindow:$Wait -PassThru)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,8 @@ InModuleScope Neo4j-Management {
}
}

Context "Uses default values" {
Mock Get-Neo4jServer { return New-Object -TypeName PSCustomObject -Property (@{'Home' = 'TestDrive:\FakeDir'; 'ServerVersion' = '99.99'; 'ServerType' = 'Community'; }) }
Mock Get-Neo4jSetting {
New-Object -TypeName PSCustomObject -Property (@{ 'ConfigurationFile'='neo4j.conf'; 'Name'='org.neo4j.server.database.location'; 'Value'='graph\db' })
} -ParameterFilter {
$Name -eq 'org.neo4j.server.database.location'
}

Mock Get-Java { return New-Object -TypeName PSCustomObject -Property (@{'java'='ignoreme'; 'args' = @();}) }
Mock Start-Process { }

Mock Start-Process -Verifiable { return @{ 'ExitCode' = 1} } -ParameterFilter {
($ArgumentList -join ' ').Contains('--into TestDrive:\FakeDir\graph\db')
}
$result = Start-Neo4jImport

It "uses default values if nothing specified" {
Assert-VerifiableMocks
}

It "returns the process exit code" {
$result | Should Be 1
}
}

Context "Uses specified graph directory" {
Mock Get-Neo4jServer { return New-Object -TypeName PSCustomObject -Property (@{'Home' = 'TestDrive:\FakeDir'; 'ServerVersion' = '99.99'; 'ServerType' = 'Community'; }) }
Mock Get-Neo4jSetting {
New-Object -TypeName PSCustomObject -Property (@{ 'ConfigurationFile'='neo4j.conf'; 'Name'='org.neo4j.server.database.location'; 'Value'='graph\db' })
} -ParameterFilter {
$Name -eq 'org.neo4j.server.database.location'
}

Mock Get-Java { return New-Object -TypeName PSCustomObject -Property (@{'java'='ignoreme'; 'args' = @();}) }
Mock Start-Process { }

Expand All @@ -99,26 +68,20 @@ InModuleScope Neo4j-Management {
}
Start-Neo4jImport --into 'TestDrive:\FakeDir\graph\db'

It "uses --into if specified" {
It "uses --into as specified" {
Assert-VerifiableMocks
}
}

Context "Appends other commands" {
Mock Get-Neo4jServer { return New-Object -TypeName PSCustomObject -Property (@{'Home' = 'TestDrive:\FakeDir'; 'ServerVersion' = '99.99'; 'ServerType' = 'Community'; }) }
Mock Get-Neo4jSetting {
New-Object -TypeName PSCustomObject -Property (@{ 'ConfigurationFile'='neo4j.conf'; 'Name'='org.neo4j.server.database.location'; 'Value'='fakedir\throwerror' })
} -ParameterFilter {
$Name -eq 'org.neo4j.server.database.location'
}

Mock Get-Java { return New-Object -TypeName PSCustomObject -Property (@{'java'='ignoreme'; 'args' = @();}) }
Mock Start-Process { }

Mock Start-Process -Verifiable { 1 } -ParameterFilter {
($ArgumentList -join ' ').Contains('-someparameter somevalue')
}
Start-Neo4jImport -someparameter somevalue
Start-Neo4jImport --into 'TestDrive:\FakeDir\graph\db' -someparameter somevalue

It "appends additional commands" {
Assert-VerifiableMocks
Expand All @@ -127,17 +90,12 @@ InModuleScope Neo4j-Management {

Context "Starts a new process by default" {
Mock Get-Neo4jServer { return New-Object -TypeName PSCustomObject -Property (@{'Home' = 'TestDrive:\FakeDir'; 'ServerVersion' = '99.99'; 'ServerType' = 'Community'; }) }
Mock Get-Neo4jSetting {
New-Object -TypeName PSCustomObject -Property (@{ 'ConfigurationFile'='neo4j.conf'; 'Name'='org.neo4j.server.database.location'; 'Value'='graph\db' })
} -ParameterFilter {
$Name -eq 'org.neo4j.server.database.location'
}
Mock Get-Java { return New-Object -TypeName PSCustomObject -Property (@{'java'='ignoreme'; 'args' = @();}) }
Mock Start-Process { }

Mock Start-Process -Verifiable -ParameterFilter { (-not $Wait) -and (-not $NoNewWindow) }

Start-Neo4jImport
Start-Neo4jImport --into 'TestDrive:\FakeDir\graph\db'

It "starts a new process by default" {
Assert-VerifiableMocks
Expand All @@ -146,16 +104,11 @@ InModuleScope Neo4j-Management {

Context "Starts shell in same process if specified" {
Mock Get-Neo4jServer { return New-Object -TypeName PSCustomObject -Property (@{'Home' = 'TestDrive:\FakeDir'; 'ServerVersion' = '99.99'; 'ServerType' = 'Community'; }) }
Mock Get-Neo4jSetting {
New-Object -TypeName PSCustomObject -Property (@{ 'ConfigurationFile'='neo4j.conf'; 'Name'='org.neo4j.server.database.location'; 'Value'='graph\db' })
} -ParameterFilter {
$Name -eq 'org.neo4j.server.database.location'
}
Mock Get-Java { return New-Object -TypeName PSCustomObject -Property (@{'java'='ignoreme'; 'args' = @();}) }
Mock Start-Process { }

Mock Start-Process -Verifiable -ParameterFilter { $Wait -and $NoNewWindow }
Start-Neo4jImport -Wait
Start-Neo4jImport -Wait --into 'TestDrive:\FakeDir\graph\db'

It "starts shell in same process if specified" {
Assert-VerifiableMocks
Expand All @@ -164,15 +117,10 @@ InModuleScope Neo4j-Management {

Context "Returns the Neo4jServer Object if -PassThru" {
Mock Get-Neo4jServer { return New-Object -TypeName PSCustomObject -Property (@{'Home' = 'TestDrive:\FakeDir'; 'ServerVersion' = '99.99'; 'ServerType' = 'Community'; }) }
Mock Get-Neo4jSetting {
New-Object -TypeName PSCustomObject -Property (@{ 'ConfigurationFile'='neo4j.conf'; 'Name'='org.neo4j.server.database.location'; 'Value'='graph\db' })
} -ParameterFilter {
$Name -eq 'org.neo4j.server.database.location'
}
Mock Get-Java { return New-Object -TypeName PSCustomObject -Property (@{'java'='ignoreme'; 'args' = @();}) }
Mock Start-Process { }

$result = Start-Neo4jImport -PassThru
$result = Start-Neo4jImport -PassThru --into 'TestDrive:\FakeDir\graph\db'

It "returns the Neo4jServer Object if -PassThru" {
$result.GetType().ToString() | Should Be 'System.Management.Automation.PSCustomObject'
Expand Down

0 comments on commit ff54181

Please sign in to comment.