Skip to content

Commit

Permalink
added cucumber test for simple neo4j application
Browse files Browse the repository at this point in the history
  • Loading branch information
jexp committed May 26, 2011
1 parent e90289a commit dcaf13c
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 5 deletions.
22 changes: 18 additions & 4 deletions apps/neo4j_app/neo4j.rb
Expand Up @@ -23,12 +23,26 @@
@root = Node.load(0)
end

get '/' do
node = Node.create("answer" => 42, "question" => "All")
@root.outgoing(:ANSWER) << node
get '/healthcheck' do
if @root
"OK"
else
"FAIL: #{ENV['VMC_SERVICES']}"
end
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>" +
@root.outgoing(:ANSWER).collect { |n| "<dt>Question: #{n.question}</dt><dd>Answer: #{n.answer}</dd>"}.join +
@root.outgoing(:ANSWER).collect { |n| "<dt>Question: #{n.question}</dt><dd>Answer: #{n.answer}</dd>"}.join +
"</dl>"
end

post '/add' do
answer = params[:answer]||'Everything'
question = params[:question]||'What?'
node = Node.create("answer" => answer, "question" => question)
@root.outgoing(:ANSWER) << node
end
11 changes: 11 additions & 0 deletions features/neo4j.feature
@@ -0,0 +1,11 @@
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

Scenario: Deploy Neo4j
Given I have deployed a Neo4j application that is backed by a Neo4j Service
When I add an answer to my application
Then I should be able see it on the start page

26 changes: 26 additions & 0 deletions features/step_definitions/neo4j_steps.rb
@@ -0,0 +1,26 @@
# Simple Neo4j Application that uses the Neo4j graph database service

Given /^I have deployed a Neo4j application that is backed by a Neo4j Service$/ do
@neo4j_app = create_app NEO4J_APP, @token
@neo4j_service = provision_neo4j_service @token
attach_provisioned_service @neo4j_app, @neo4j_service, @token
upload_app @neo4j_app, @token
start_app @neo4j_app, @token
expected_health = 1.0
health = poll_until_done @neo4j_app, expected_health, @token
health.should == expected_health
end

When /^I add an answer to my application$/ do
uri = get_uri @app, "add"
post_record uri, { :question => 'Q1', :answer => 'A1'}
end

Then /^I should be able see it on the start page$/ do
uri = get_uri @app, ""
contents = get_uri_contents uri
contents.should_not == nil
contents.include?("Q1").should_be true
contents.include?("A1").should_be true
contents.close
end
18 changes: 18 additions & 0 deletions features/support/env.rb
Expand Up @@ -33,6 +33,7 @@
GRAILS_APP = "grails_app"
ROO_APP = "roo_app"
SIMPLE_ERLANG_APP = "mochiweb_test"
NEO4J_APP = "neo4j_app"

After do
AppCloudHelper.instance.delete_user
Expand Down Expand Up @@ -95,6 +96,10 @@
AppCloudHelper.instance.delete_app_internal SIMPLE_ERLANG_APP
end

After("@creates_neo4j_app") do
AppCloudHelper.instance.delete_app_internal NEO4J_APP
end

at_exit do
AppCloudHelper.instance.cleanup
end
Expand Down Expand Up @@ -162,6 +167,7 @@ def cleanup
delete_app_internal(DBRAILS_BROKEN_APP)
delete_app_internal(GRAILS_APP)
delete_app_internal(ROO_APP)
delete_app_internal(NEO4J_APP)
delete_user
end

Expand Down Expand Up @@ -446,6 +452,18 @@ def get_services token
services
end

def provision_neo4j_service token
service_manifest = {
:type=>"graphdatabase",
:vendor=>"neo4j",
:tier=>"free",
:version=>"1.4",
:name=>"#{@namespace}neo4j_app"}
@client.add_service_internal @services_uri, service_manifest, auth_hdr(token)
puts "Provisioned service #{service_manifest}"
service_manifest
end

def provision_db_service token
name = "#{@namespace}#{@app || 'simple_db_app'}"
service_manifest = {
Expand Down
6 changes: 6 additions & 0 deletions features/support/testconfig.yml
Expand Up @@ -62,7 +62,13 @@ roo_app:
startup: "thin start"
memory: 256


mochiweb_test:
framework: "otp_rebar"
startup: erlangR14B02
memory: 64

neo4j_app:
framework: "http://b20nine.com/unknown"
startup: "ruby neo4j.rb"
memory: 256
2 changes: 2 additions & 0 deletions profiles/acdev/cloud_controller.yml.erb
Expand Up @@ -46,4 +46,6 @@ builtin_services:
token: "0xdeadbeef"
mongodb:
token: "0xdeadbeef"
neo4j:
token: "0xdeadbeef"

14 changes: 14 additions & 0 deletions 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
13 changes: 13 additions & 0 deletions 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
4 changes: 3 additions & 1 deletion profiles/mac/cloud_controller.yml.erb
Expand Up @@ -39,4 +39,6 @@ builtin_services:
token: "0xdeadbeef"
mongodb:
token: "0xdeadbeef"

neo4j:
token: "0xdeadbeef"

14 changes: 14 additions & 0 deletions 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
13 changes: 13 additions & 0 deletions 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
2 changes: 2 additions & 0 deletions rakelib/build_helpers.rake
Expand Up @@ -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|
Expand Down

0 comments on commit dcaf13c

Please sign in to comment.