Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Neo4j tests

Squashed commit of the following:

commit 4b285fea728c62830c49bd0b2eae66ae9a17aaed
Merge: 4c1e548 fb6860e
Author: Patrick Bozeman <pbozeman@vmware.com>
Date:   Tue Aug 2 11:49:50 2011 -0700

    Merge remote-tracking branch 'jexp/master'

    Contains manual edits during the merge to bring up-to-date
    with the rest of vcap-tests and vcap-services.

    Conflicts:
    	features/support/env.rb
    	features/support/testconfig.yml

    Change-Id: I1c22050996f37f82825bf382ec75c1ad4325d70c

commit fb6860e
Author: Michael Hunger <github@jexp.de>
Date:   Fri May 27 23:02:19 2011 +0200

    finished simple neo4j cucumber test

commit 87cfa4f
Author: CloudFoundry <cloud@cloudfoundry.hosted.neo4j.org>
Date:   Fri May 27 14:43:40 2011 +0200

    updated neo4j test app

commit dcaf13c
Author: Michael Hunger <github@jexp.de>
Date:   Thu May 26 04:22:03 2011 +0200

    added cucumber test for simple neo4j application

commit e90289a
Author: Michael Hunger <github@jexp.de>
Date:   Fri May 13 15:23:55 2011 +0200

    added neo4j sample app

Change-Id: I8e438f1b2c3284006c1ea41ab81fe138dbdfd44d
  • Loading branch information...
commit 7c28f42a25add3bc583934b309f9c8a9f7e1f13b 1 parent 077f6ec
@jexp jexp authored Patrick Bozeman committed
View
3  apps/neo4j_app/Gemfile
@@ -0,0 +1,3 @@
+source "http://rubygems.org"
+gem 'neography'
+gem 'sinatra'
View
22 apps/neo4j_app/Gemfile.lock
@@ -0,0 +1,22 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ crack (0.1.8)
+ httparty (0.7.7)
+ crack (= 0.1.8)
+ json (1.5.1)
+ neography (0.0.13)
+ httparty (~> 0.7.3)
+ json
+ rack (1.2.2)
+ sinatra (1.2.6)
+ rack (~> 1.1)
+ tilt (>= 1.2.2, < 2.0)
+ tilt (1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ neography
+ sinatra
View
94 apps/neo4j_app/neo4j.rb
@@ -0,0 +1,94 @@
+require 'rubygems'
+require 'sinatra'
+require 'neography'
+require 'json'
+
+include Neography
+
+configure do
+ set :show_exceptions, false
+end
+
+def get_neo
+ begin
+ if ENV['VCAP_SERVICES']
+ services = JSON.parse(ENV['VCAP_SERVICES'])
+ neo4j = services['neo4j-1.4'][0]['credentials']
+ else
+ neo4j = {}
+ end
+#$stderr.puts ENV['VCAP_SERVICES']
+
+ Neography::Config.server = neo4j['hostname'] || 'localhost'
+ Neography::Config.port = (neo4j['port'] || "7474").to_i
+ Neography::Config.authentication = 'basic'
+ Neography::Config.username = neo4j['username']||"test"
+ Neography::Config.password = neo4j['password']||"test"
+
+ @neo = Rest.new
+#$stderr.puts @neo.configuration
+ @neo
+ rescue Exception => e
+ $stderr.puts "Neo4j Exception #{e}"
+ nil
+ end
+end
+
+before do
+ get_neo
+end
+
+get '/healthcheck' do
+ begin
+ Node::load(0)
+ "OK"
+ rescue Exception => e
+ "FAIL: #{ENV['VCAP_SERVICES']} #{e}"
+ end
+end
+
+def get_root
+ Node::load(0)
+end
+
+def new_node(question,answer)
+ nil unless question && answer
+ node = Node.create("answer" => answer, "question" => question)
+ get_root.outgoing(:ANSWER) << node
+ node
+end
+
+
+get '/' do
+ "<h2>Add a Q&amp;A!</h2>" +
+ "<form method='post' action='/add'>Question: <input name=question/> Answer: <input type=text name=answer/><input type=submit/></form>" +
+ "<h1>Answers from Neo4j!</h1>" +
+ "<dl>" +
+ get_root.outgoing(:ANSWER).collect { |n| "<dt>Question: #{n.question}</dt><dd>Answer: #{n.answer}</dd>"}.join +
+ "</dl>"
+end
+
+get '/question', :provides => :json do
+ content_type :json
+ get_root.outgoing(:ANSWER).collect{ |n| { :question => n.question, :answer => n.answer}}.to_json
+end
+
+get '/question/:id', :provides => :json do |id|
+ content_type :json
+ node = Node::load(id)
+ 404 unless node
+ { :question => node.question, :answer => node.answer}.to_json
+end
+
+post '/question' do
+ data = JSON.parse request.body.read
+ node = new_node(data['question'],data['answer'])
+ status 400 unless node
+ url("/question/#{node.neo_id}")
+end
+
+post '/add' do
+ node = new_node(params[:question],params[:answer])
+ halt 400 unless node
+ redirect to("/"), 201
+end
View
BIN  apps/neo4j_app/vendor/cache/crack-0.1.8.gem
Binary file not shown
View
BIN  apps/neo4j_app/vendor/cache/httparty-0.7.7.gem
Binary file not shown
View
BIN  apps/neo4j_app/vendor/cache/json-1.5.1.gem
Binary file not shown
View
BIN  apps/neo4j_app/vendor/cache/neography-0.0.13.gem
Binary file not shown
View
BIN  apps/neo4j_app/vendor/cache/rack-1.2.2.gem
Binary file not shown
View
BIN  apps/neo4j_app/vendor/cache/sinatra-1.2.6.gem
Binary file not shown
View
BIN  apps/neo4j_app/vendor/cache/tilt-1.3.gem
Binary file not shown
View
13 features/neo4j.feature
@@ -0,0 +1,13 @@
+Feature: Neo4j service binding and app deployment
+
+ In order to use Neo4j in AppCloud
+ As the VMC user
+ I want to deploy my app against a Neo4j service
+
+ @creates_neo4j_app @creates_neo4j_service
+ Scenario: Deploy Neo4j
+ Given I have registered and logged in
+ Given I have provisioned a Neo4j service
+ Given I have deployed a Neo4j application that is bound to this service
+ When I add an answer to my application
+ Then I should be able to retrieve it
View
40 features/step_definitions/neo4j_steps.rb
@@ -0,0 +1,40 @@
+# Simple Neo4j Application that uses the Neo4j graph database service
+
+Given /^I have provisioned a Neo4j service$/ do
+ pending unless find_service 'neo4j'
+ @neo4j_service = provision_neo4j_service @token
+ @neo4j_service.should_not == nil
+end
+
+Given /^I have deployed a Neo4j application that is bound to this service$/ do
+ @app = create_app NEO4J_APP, @token
+ attach_provisioned_service @app, @neo4j_service, @token
+ upload_app @app, @token
+ start_app @app, @token
+ expected_health = 1.0
+ health = poll_until_done @app, expected_health, @token
+ health.should == expected_health
+end
+
+When /^I add an answer to my application$/ do
+ uri = get_uri(@app, "question")
+ r = post_record_no_close(uri, { :question => 'Q1', :answer => 'A1'})
+ r.response_code.should == 200
+ @question_id = r.body_str.split(/\//).last
+ r.close
+end
+
+Then /^I should be able to retrieve it$/ do
+ uri = get_uri @app, "question/#{@question_id}"
+ response = get_uri_contents uri
+ response.should_not == nil
+ response.response_code.should == 200
+ contents = JSON.parse response.body_str
+ contents["question"].should == "Q1"
+ contents["answer"].should == "A1"
+ response.close
+end
+
+After("@creates_neo4j_service") do |scenario|
+ delete_app_services if @neo4j_service
+end
View
24 features/support/env.rb
@@ -45,6 +45,7 @@
SIMPLE_LIFT_APP = "simple-lift-app"
LIFT_DB_APP = "lift-db-app"
TOMCAT_VERSION_CHECK_APP="tomcat-version-check-app"
+NEO4J_APP = "neo4j_app"
SIMPLE_PYTHON_APP = "simple_wsgi_app"
PYTHON_APP_WITH_DEPENDENCIES = "wsgi_app_with_requirements"
SIMPLE_DJANGO_APP = "simple_django_app"
@@ -121,6 +122,10 @@
AppCloudHelper.instance.delete_app_internal TOMCAT_VERSION_CHECK_APP
end
+After("@creates_neo4j_app") do
+ AppCloudHelper.instance.delete_app_internal NEO4J_APP
+end
+
After("@creates_wsgi_app") do
AppCloudHelper.instance.delete_app_internal SIMPLE_PYTHON_APP
end
@@ -207,6 +212,7 @@ def cleanup
delete_app_internal(SIMPLE_LIFT_APP)
delete_app_internal(LIFT_DB_APP)
delete_app_internal(TOMCAT_VERSION_CHECK_APP)
+ delete_app_internal(NEO4J_APP)
delete_app_internal(SIMPLE_PYTHON_APP)
delete_app_internal(PYTHON_APP_WITH_DEPENDENCIES)
delete_app_internal(SIMPLE_DJANGO_APP)
@@ -622,6 +628,17 @@ def provision_mongodb_service token
service_manifest
end
+ def provision_neo4j_service token
+ name = "#{@namespace}#{@app || 'simple_neo4j_app'}neo4j"
+ @client.create_service(:neo4j, name)
+ service_manifest = {
+ :vendor=>"neo4j",
+ :tier=>"free",
+ :version=>"1.4",
+ :name=>name
+ }
+ end
+
def provision_postgresql_service
name = "#{@namespace}#{@app || 'simple_db_app'}postgresql"
@client.create_service(:postgresql, name)
@@ -779,10 +796,15 @@ def post_uri uri, data
easy
end
- def post_record uri, data_hash
+ def post_record_no_close uri, data_hash
easy = Curl::Easy.new
easy.url = uri
easy.http_post(data_hash.to_json)
+ easy
+ end
+
+ def post_record uri, data_hash
+ easy = post_record_no_close(uri,data_hash)
easy.close
end
View
6 features/support/testconfig.yml
@@ -62,6 +62,7 @@ roo_app:
startup: "thin start"
memory: 256
+
mochiweb_test:
framework: "otp_rebar"
startup: erlangR14B02
@@ -108,6 +109,11 @@ my_test_app_env_test_app:
startup: "ruby foo.rb"
memory: 64
+neo4j_app:
+ framework: "http://b20nine.com/unknown"
+ startup: "ruby neo4j.rb"
+ memory: 256
+
simple_wsgi_app:
framework: "wsgi"
View
2  profiles/acdev/cloud_controller.yml.erb
@@ -46,4 +46,6 @@ builtin_services:
token: "0xdeadbeef"
mongodb:
token: "0xdeadbeef"
+ neo4j:
+ token: "0xdeadbeef"
View
14 profiles/acdev/services/neo4j/neo4j_gateway.yml.erb
@@ -0,0 +1,14 @@
+---
+cloud_controller_uri: <%= config.controller_host %>
+service:
+ name: neo4j
+ version: "1.4"
+ description: 'Neo4j NOSQL store'
+ plans: ['free']
+ tags: ['neo4j', 'neo4j-1.4', 'nosql']
+host: localhost
+token: "0xdeadbeef"
+mbus: <%= config.nats_uri %>
+log_level: DEBUG
+pid: <%= config.working_dir %>/sys/run/neo4j_service.pid
+node_timeout: 10
View
13 profiles/acdev/services/neo4j/neo4j_node.yml.erb
@@ -0,0 +1,13 @@
+---
+local_db: sqlite3:<%= config.working_dir %>/services/neo4j/neo4j_node.db
+mbus: <%= config.nats_uri %>
+base_dir: <%= config.working_dir %>/services/neo4j/instances
+log_level: DEBUG
+pid: <%= config.working_dir %>/sys/run/neo4j_node.pid
+available_memory: 4096
+max_memory: 128
+node_id: neo4j_node_1
+neo4j_path: <%= config.working_dir %>/services/neo4j
+port_range:
+ first: 45000
+ last: 55000
View
3  profiles/mac/cloud_controller.yml.erb
@@ -39,4 +39,5 @@ builtin_services:
token: "0xdeadbeef"
mongodb:
token: "0xdeadbeef"
-
+ neo4j:
+ token: "0xdeadbeef"
View
14 profiles/mac/services/neo4j/neo4j_gateway.yml.erb
@@ -0,0 +1,14 @@
+---
+cloud_controller_uri: <%= config.controller_host %>
+service:
+ name: neo4j
+ version: "1.4"
+ description: 'Neo4j NOSQL store'
+ plans: ['free']
+ tags: ['neo4j', 'neo4j-1.4', 'nosql']
+host: localhost
+token: "0xdeadbeef"
+mbus: <%= config.nats_uri %>
+log_level: DEBUG
+pid: <%= config.working_dir %>/sys/run/neo4j_service.pid
+node_timeout: 10
View
13 profiles/mac/services/neo4j/neo4j_node.yml.erb
@@ -0,0 +1,13 @@
+---
+local_db: sqlite3:<%= config.working_dir %>/services/neo4j/neo4j_node.db
+mbus: <%= config.nats_uri %>
+base_dir: <%= config.working_dir %>/services/neo4j/instances
+log_level: DEBUG
+pid: <%= config.working_dir %>/sys/run/neo4j_node.pid
+available_memory: 4096
+max_memory: 128
+node_id: neo4j_node_1
+neo4j_path: <%= config.working_dir %>/services/neo4j
+port_range:
+ first: 45000
+ last: 55000
View
2  rakelib/build_helpers.rake
@@ -137,9 +137,11 @@ export BUNDLE_PATH=#{BuildConfig.bundle_path}
#{start_command_for 'redis_node'}
#{start_command_for 'mysql_node'}
#{start_command_for 'mongodb_node'}
+#{start_command_for 'neo4j_node'}
#{start_command_for 'redis_gateway'}
#{start_command_for 'mysql_gateway'}
#{start_command_for 'mongodb_gateway'}
+#{start_command_for 'neo4j_gateway'}
START
File.open(BuildConfig.service_startup_script, 'w') do |fh|
Please sign in to comment.
Something went wrong with that request. Please try again.