Class: Neo4jTest::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4j_test_server/neo4j_server.rb

Constant Summary collapse

ServerError =

Raised if #stop is called but the server is not running

Class.new(RuntimeError)
AlreadyRunningError =
Class.new(ServerError)
NotRunningError =
Class.new(ServerError)
JavaMissing =
Class.new(ServerError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ed = 'community-2.2.0') ⇒ Server

Returns a new instance of Server.



18
19
20
21
# File 'lib/neo4j_test_server/neo4j_server.rb', line 18

def initialize(ed = 'community-2.2.0')
  ensure_java_installed
  self.edition = ed
end

Instance Attribute Details

#bind_addressObject



34
35
36
# File 'lib/neo4j_test_server/neo4j_server.rb', line 34

def bind_address
  @bind_address ||= '127.0.0.1'
end

#editionObject

Returns the value of attribute edition.



14
15
16
# File 'lib/neo4j_test_server/neo4j_server.rb', line 14

def edition
  @edition
end

#neo4j_data_dir=(value) ⇒ Object (writeonly)

Sets the attribute neo4j_data_dir

Parameters:

  • value

    the value to set the attribute neo4j_data_dir to.



16
17
18
# File 'lib/neo4j_test_server/neo4j_server.rb', line 16

def neo4j_data_dir=(value)
  @neo4j_data_dir = value
end

#neo4j_home=(value) ⇒ Object (writeonly)

Sets the attribute neo4j_home

Parameters:

  • value

    the value to set the attribute neo4j_home to.



16
17
18
# File 'lib/neo4j_test_server/neo4j_server.rb', line 16

def neo4j_home=(value)
  @neo4j_home = value
end

#neo4j_jar=(value) ⇒ Object (writeonly)

Sets the attribute neo4j_jar

Parameters:

  • value

    the value to set the attribute neo4j_jar to.



16
17
18
# File 'lib/neo4j_test_server/neo4j_server.rb', line 16

def neo4j_jar=(value)
  @neo4j_jar = value
end

#portObject



38
39
40
# File 'lib/neo4j_test_server/neo4j_server.rb', line 38

def port
  @port ||= '7474'
end

Instance Method Details

#bootstrapObject



27
28
29
30
31
32
# File 'lib/neo4j_test_server/neo4j_server.rb', line 27

def bootstrap
  unless @bootstrapped
    Neo4jTest::Installer.bootstrap edition
    @bootstrapped = true
  end
end

#ensure_java_installedObject



82
83
84
85
86
87
88
89
90
# File 'lib/neo4j_test_server/neo4j_server.rb', line 82

def ensure_java_installed
  unless defined?(@java_installed)
    @java_installed = Neo4jTest::Java.installed?
    unless @java_installed
      raise JavaMissing.new('You need a Java Runtime Environment to run the Solr server')
    end
  end
  @java_installed
end

#install_locationObject



92
93
94
# File 'lib/neo4j_test_server/neo4j_server.rb', line 92

def install_location
  Neo4jTest::Installer.install_location
end

#startObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/neo4j_test_server/neo4j_server.rb', line 46

def start
  bootstrap

  puts 'Starting Neo4j...'
  if OS::Underlying.windows?
    start_windows_server(start_command)
  else
    start_starnix_server(start_command)
  end
end

#start_commandObject



42
43
44
# File 'lib/neo4j_test_server/neo4j_server.rb', line 42

def start_command
  @start_command ||= 'start'
end

#start_starnix_server(command) ⇒ Object



78
79
80
# File 'lib/neo4j_test_server/neo4j_server.rb', line 78

def start_starnix_server(command)
  `#{install_location}/bin/neo4j #{command}`
end

#start_windows_server(command) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/neo4j_test_server/neo4j_server.rb', line 69

def start_windows_server(command)
  if `reg query "HKU\\S-1-5-19"`.size > 0
    `#{install_location}/bin/Neo4j.bat #{command}`  # start service
  else
    puts 'Starting Neo4j directly, not as a service.'
    `#{install_location}/bin/Neo4j.bat`
  end
end

#stopObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/neo4j_test_server/neo4j_server.rb', line 57

def stop
  if OS::Underlying.windows?
    if `reg query "HKU\\S-1-5-19"`.size > 0
      `#{install_location}/bin/Neo4j.bat stop`  # stop service
    else
      puts 'You do not have administrative rights to stop the Neo4j Service'
    end
  else
    `#{install_location}/bin/neo4j stop`
  end
end

#to_sObject



23
24
25
# File 'lib/neo4j_test_server/neo4j_server.rb', line 23

def to_s
  "http://#{bind_address}:#{port}" unless bind_address.empty? && port.empty?
end