-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
245 additions
and
13 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
97 changes: 97 additions & 0 deletions
97
...tandalone/src/main/distribution/shell-scripts/bin/Neo4j-Management/Update-Neo4jServer.ps1
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,97 @@ | ||
# Copyright (c) 2002-2018 "Neo Technology," | ||
# Network Engine for Objects in Lund AB [http://neotechnology.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/>. | ||
|
||
|
||
<# | ||
.SYNOPSIS | ||
Update an installed Neo4j Server Windows Service | ||
.DESCRIPTION | ||
Update an installed Neo4j Server Windows Service | ||
.PARAMETER Neo4jServer | ||
An object representing a valid Neo4j Server | ||
.EXAMPLE | ||
Update-Neo4jServer $ServerObject | ||
Update the Neo4j Windows Service for the Neo4j installation at $ServerObject | ||
.OUTPUTS | ||
System.Int32 | ||
0 = Service is successfully updated | ||
non-zero = an error occured | ||
.NOTES | ||
This function is private to the powershell module | ||
#> | ||
Function Update-Neo4jServer | ||
{ | ||
[cmdletBinding(SupportsShouldProcess=$false,ConfirmImpact='Medium')] | ||
param ( | ||
[Parameter(Mandatory=$true,ValueFromPipeline=$true)] | ||
[PSCustomObject]$Neo4jServer | ||
) | ||
|
||
Begin | ||
{ | ||
} | ||
|
||
Process | ||
{ | ||
$Name = Get-Neo4jWindowsServiceName -Neo4jServer $Neo4jServer -ErrorAction Stop | ||
|
||
$result = Get-Service -Name $Name -ComputerName '.' -ErrorAction 'SilentlyContinue' | ||
if ($result -ne $null) | ||
{ | ||
$prunsrv = Get-Neo4jPrunsrv -Neo4jServer $Neo4jServer -ForServerUpdate | ||
if ($prunsrv -eq $null) { throw "Could not determine the command line for PRUNSRV" } | ||
|
||
Write-Verbose "Update installed Neo4j service with command line $($prunsrv.cmd) $($prunsrv.args)" | ||
$stdError = New-Neo4jTempFile -Prefix 'stderr' | ||
Write-Verbose $prunsrv | ||
$result = (Start-Process -FilePath $prunsrv.cmd -ArgumentList $prunsrv.args -Wait -NoNewWindow -PassThru -WorkingDirectory $Neo4jServer.Home -RedirectStandardError $stdError) | ||
Write-Verbose "Returned exit code $($result.ExitCode)" | ||
|
||
# Process the output | ||
if ($result.ExitCode -eq 0) { | ||
Write-Host "Neo4j service updated" | ||
} else { | ||
Write-Host "Neo4j service did not update" | ||
# Write out STDERR if it did not update | ||
Get-Content -Path $stdError -ErrorAction 'SilentlyContinue' | ForEach-Object -Process { | ||
Write-Host $_ | ||
} | ||
} | ||
|
||
# Remove the temp file | ||
If (Test-Path -Path $stdError) { Remove-Item -Path $stdError -Force | Out-Null } | ||
|
||
Write-Output $result.ExitCode | ||
} else { | ||
Write-Host "Service update failed - service '$Name' not found" | ||
Write-Output 1 | ||
} | ||
} | ||
|
||
End | ||
{ | ||
} | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
packaging/standalone/src/tests/Neo4j-Management/Run-Tests.ps1
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,26 @@ | ||
# Copyright (c) 2002-2018 "Neo Technology," | ||
# Network Engine for Objects in Lund AB [http://neotechnology.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/>. | ||
|
||
|
||
# Run tests in this directory and subdirectories. | ||
# Usage: | ||
# powershell.exe \\path\to\Run-Tests.ps1 | ||
# powershell.exe -NonInteractive -ExecutionPolicy ByPass -File \\path\to\Run-Tests.ps1 | ||
|
||
$here = Split-Path -Parent $MyInvocation.MyCommand.Definition | ||
Invoke-Pester -OutputFile pester-nunit.xml -OutputFormat NUnitXml -EnableExit -Script $here |
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
88 changes: 88 additions & 0 deletions
88
packaging/standalone/src/tests/Neo4j-Management/unit/Update-Neo4jServer.Tests.ps1
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,88 @@ | ||
# Copyright (c) 2002-2018 "Neo Technology," | ||
# Network Engine for Objects in Lund AB [http://neotechnology.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/>. | ||
|
||
|
||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") | ||
$common = Join-Path (Split-Path -Parent $here) 'Common.ps1' | ||
. $common | ||
|
||
Import-Module "$src\Neo4j-Management.psm1" | ||
|
||
InModuleScope Neo4j-Management { | ||
Describe "Update-Neo4jServer" { | ||
|
||
# Setup mocking environment | ||
# Mock Java environment | ||
$javaHome = global:New-MockJavaHome | ||
Mock Get-Neo4jEnv { $javaHome } -ParameterFilter { $Name -eq 'JAVA_HOME' } | ||
Mock Set-Neo4jEnv { } | ||
Mock Test-Path { $false } -ParameterFilter { | ||
$Path -like 'Registry::*\JavaSoft\Java Runtime Environment' | ||
} | ||
Mock Get-ItemProperty { $null } -ParameterFilter { | ||
$Path -like 'Registry::*\JavaSoft\Java Runtime Environment*' | ||
} | ||
# Mock Neo4j environment | ||
Mock Get-Neo4jEnv { $global:mockNeo4jHome } -ParameterFilter { $Name -eq 'NEO4J_HOME' } | ||
Mock Start-Process { throw "Should not call Start-Process mock" } | ||
|
||
Context "Invalid or missing specified neo4j installation" { | ||
$serverObject = global:New-InvalidNeo4jInstall | ||
|
||
It "throws if invalid or missing neo4j directory" { | ||
{ Update-Neo4jServer -Neo4jServer $serverObject -ErrorAction Stop } | Should Throw | ||
} | ||
} | ||
|
||
Context "Non-existing service" { | ||
Mock Get-Service -Verifiable { return $null } | ||
$serverObject = global:New-MockNeo4jInstall | ||
$result = Update-Neo4jServer -Neo4jServer $serverObject | ||
|
||
It "returns 1 for service that does not exist" { | ||
$result | Should Be 1 | ||
Assert-VerifiableMocks | ||
} | ||
} | ||
|
||
Context "Update service failure" { | ||
Mock Get-Service -Verifiable { return "Fake service" } | ||
Mock Start-Process -Verifiable { throw "Error reconfiguring" } | ||
$serverObject = global:New-MockNeo4jInstall | ||
|
||
It "throws when update encounters an error" { | ||
{ Update-Neo4jServer -Neo4jServer $serverObject } | Should Throw | ||
Assert-VerifiableMocks | ||
} | ||
} | ||
|
||
Context "Update service success" { | ||
Mock Get-Service -Verifiable { return "Fake service" } | ||
Mock Start-Process -Verifiable { @{'ExitCode' = 0} } | ||
$serverObject = global:New-MockNeo4jInstall | ||
$result = Update-Neo4jServer -Neo4jServer $serverObject | ||
|
||
It "returns 0 when successfully updated" { | ||
$result | Should Be 0 | ||
Assert-VerifiableMocks | ||
} | ||
} | ||
|
||
} | ||
} |