Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup integration tests #155

Merged
merged 4 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ gem 'heroku_hatchet'
gem 'rspec-retry'
gem 'rspec-expectations'
gem 'parallel_split_test'
gem 'java-properties'
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ GEM
rrrretry (~> 1)
thor (~> 1)
threaded (~> 0)
java-properties (0.2.1)
moneta (1.0.0)
multi_json (1.15.0)
parallel (1.19.2)
Expand Down Expand Up @@ -50,6 +51,7 @@ PLATFORMS

DEPENDENCIES
heroku_hatchet
java-properties
parallel_split_test
rspec-expectations
rspec-retry
Expand Down
18 changes: 9 additions & 9 deletions hatchet.lock
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
- - spec/fixtures/repos/db/java-apache-dbcp-sample
- - test/spec/fixtures/repos/db/java-apache-dbcp-sample
- bc8ef681cf36bf3d78dd94ea514e6d26c649bbb1
- - spec/fixtures/repos/java/java-servlets-sample
- - test/spec/fixtures/repos/java/java-servlets-sample
- 1cc2843067197d939a1218f1bbe63f5ed28c6111
- - spec/fixtures/repos/java/korvan
- - test/spec/fixtures/repos/java/korvan
- 1a99202ecc10f9a27ad3fedb30403b3f4bcb4750
- - spec/fixtures/repos/java/libpng-test
- - test/spec/fixtures/repos/java/libpng-test
- 2afd98d3a953fd49f9a2f77380a639ae3091ec98
- - spec/fixtures/repos/java/maven-polyglot
- - test/spec/fixtures/repos/java/maven-polyglot
Malax marked this conversation as resolved.
Show resolved Hide resolved
- ecab985c6fa8678b69cc6764f939fd76a9de70ee
- - spec/fixtures/repos/java/webapp-runner-sample
- 493b385f3621d78e150ef12e2ac5362381e2c085
- - spec/fixtures/repos/spring/spring-boot-executable
- - test/spec/fixtures/repos/java/webapp-runner-sample
- 02b128a87db6df7776baafdcb9a69504e4a41a58
- - test/spec/fixtures/repos/spring/spring-boot-executable
- e10d57ce128ad43225b2e0c6c3a0c0d0aa71ff9e
- - spec/fixtures/repos/spring/spring-boot-webapp-runner
- - test/spec/fixtures/repos/spring/spring-boot-webapp-runner
- dd3ec06e76b562bd3734ad5dc576b416ff1559ea
59 changes: 20 additions & 39 deletions test/spec/agent_spec.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,29 @@
require_relative 'spec_helper'
require_relative "spec_helper"

describe "JavaAgent" do
describe "Heroku's Java buildpack" do
context "using OpenJDK #{DEFAULT_OPENJDK_VERSION}" do
it "supports heroku-javaagent" do
Hatchet::Runner.new("webapp-runner-sample", stack: ENV["HEROKU_TEST_STACK"]).tap do |app|
app.before_deploy do
set_java_version(DEFAULT_OPENJDK_VERSION)

%w{1.8}.each do |version|
context "on #{version}" do
let(:app) { @app }

before(:all) do
@app = Hatchet::Runner.new("webapp-runner-sample")
init_app(@app)
javaagent="heroku-javaagent-2.0.jar"
Dir.chdir(@app.directory) do
`curl --silent -O -L https://repo1.maven.org/maven2/com/heroku/agent/heroku-javaagent/2.0/#{javaagent}`
`git add #{javaagent}`

# edit the procfile
File.open('Procfile', 'w') do |f|
f.puts <<-EOF
web: java $JAVA_OPTS -javaagent:#{javaagent}=stdout=true,lxmem=true -jar target/dependency/webapp-runner.jar --port $PORT target/*.war
EOF
end
`git add Procfile`
`git commit -m "adding java agent"`
java_agent_filename="heroku-javaagent-2.0.jar"
run("curl --silent -O -L https://repo1.maven.org/maven2/com/heroku/agent/heroku-javaagent/2.0/#{java_agent_filename}")
write_to_procfile("web: java $JAVA_OPTS -javaagent:#{java_agent_filename}=stdout=true,lxmem=true -jar target/dependency/webapp-runner.jar --port $PORT target/*.war")
end
@app.deploy
end

after(:all) do
@app.teardown!
end
app.deploy do
expect(app.output).to include("BUILD SUCCESS")
expect(http_get(app)).to eq("Hello from Java!")

it "deploys successfully" do
expect(app.output).to include("BUILD SUCCESS")
sleep(10) # :( for the logs really
expect(successful_body(app)).to eq("Hello from Java!")
expect(app).to be_deployed
end
# We need to wait a moment for the logs to show up
sleep(10)
Malax marked this conversation as resolved.
Show resolved Hide resolved

it "logs memory usage", :retry => 10, :retry_wait => 5 do
logs = `heroku logs -n 2000 -a #{app.name}`
expect(logs).
to include("measure.mem.jvm.heap.used=").
and include("measure.mem.jvm.nonheap.used=").
and include("measure.threads.jvm.total=")
expect(run("heroku logs -n 2000 -a #{app.name}"))
.to include("measure.mem.jvm.heap.used=")
.and include("measure.mem.jvm.nonheap.used=")
.and include("measure.threads.jvm.total=")
end
end
end
end
Expand Down
29 changes: 11 additions & 18 deletions test/spec/db_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
require_relative 'spec_helper'
require_relative "spec_helper"

describe "Java" do
before(:each) do
set_java_version(app.directory, jdk_version)
init_app(app)
end
describe "Heroku's Java buildpack" do
context "using OpenJDK #{DEFAULT_OPENJDK_VERSION}" do
it "should use connection pool" do
Hatchet::Runner.new("java-apache-dbcp-sample", stack: ENV["HEROKU_TEST_STACK"]).tap do |app|
app.before_deploy do
set_java_version(DEFAULT_OPENJDK_VERSION)
end

%w{1.8}.each do |version|
context "on jdk-#{version}" do
let(:app) { Hatchet::Runner.new("java-apache-dbcp-sample") }
let(:jdk_version) { version }
it "should use connection pool" do
app.deploy do |app|
expect(app.output).to include("Installing JDK #{jdk_version}")
app.deploy do
expect(app.output).to include("Installing JDK #{DEFAULT_OPENJDK_VERSION}")
expect(app.output).to include("Installing Maven")
expect(app.output).not_to include("BUILD FAILURE")
expect(app.output).to include("BUILD SUCCESS")

expect(successful_body(app, :path => "db")).to match("Read from DB:")

expect(app).to be_deployed
expect(http_get(app, :path => "db")).to match("Read from DB:")
end
end
end
Expand Down
155 changes: 67 additions & 88 deletions test/spec/java_spec.rb
Original file line number Diff line number Diff line change
@@ -1,126 +1,105 @@
require_relative 'spec_helper'
require_relative "spec_helper"

describe "Java" do

def expect_successful_maven(app, jdk_version)
expect(app.output).to include("Installing JDK #{jdk_version}")
expect(app.output).not_to include("BUILD FAILURE")
expect(app.output).to include("BUILD SUCCESS")
end

["1.7", "1.8", "11"].each do |jdk_version|
context "on jdk-#{jdk_version}" do
it "should reinstall maven" do
describe "Heroku's Java buildpack" do
OPENJDK_VERSIONS.each do |openjdk_version|
context "using OpenJDK #{openjdk_version}" do
it "should not reinstall Maven" do
Hatchet::Runner.new("java-servlets-sample", stack: ENV["HEROKU_TEST_STACK"]).tap do |app|
app.before_deploy do
set_java_version(Dir.pwd, jdk_version)
set_java_version(openjdk_version)
end

app.deploy do |app|
expect_successful_maven(app, jdk_version)
app.deploy do
expect(app.output).to include("Installing JDK #{openjdk_version}")
expect(app.output).to include("BUILD SUCCESS")
expect(successful_body(app)).to eq("Hello from Java!")
# Commit ed358d63b384bc7c8cf96be61ada768f4cc55a19 on the example app added Maven Wrapper to
# the project, bypassing Maven installation entirely.
# expect(app.output).to include("Installing Maven")
Malax marked this conversation as resolved.
Show resolved Hide resolved
expect(app.output).not_to include("BUILD FAILURE")
expect(http_get(app)).to eq("Hello from Java!")

app.commit!
app.push!

expect_successful_maven(app, jdk_version)
expect(app.output).not_to include("Installing Maven")
expect(app.output).to include("Installing JDK #{openjdk_version}")
expect(app.output).to include("BUILD SUCCESS")

expect(successful_body(app)).to eq("Hello from Java!")

expect(app.run("env", { :heroku => { "exit-code" => Hatchet::App::SkipDefaultOption }})). # work around a CLI bug that doesn't allow --exit-code when invoking a process type via "heroku run"
to include(%q{DATABASE_URL})
expect(app.output).not_to include("BUILD FAILURE")
expect(app.output).not_to include("Installing Maven")
expect(http_get(app)).to eq("Hello from Java!")
end
end
end
end
end

context "korvan" do
["1.8", "11", "13", "15"].each do |jdk_version|
context "on jdk-#{jdk_version}" do
it "runs commands" do
Hatchet::Runner.new("korvan", stack: ENV["HEROKU_TEST_STACK"], run_multi: true).tap do |app|
app.before_deploy do
set_java_version(Dir.pwd, jdk_version)
end

app.deploy do |app|
expect_successful_maven(app, jdk_version)
it "builds and executes Korvan test commands successfully" do
Hatchet::Runner.new("korvan", stack: ENV["HEROKU_TEST_STACK"]).tap do |app|
app.before_deploy do
set_java_version(openjdk_version)
end

expect(successful_body(app)).to eq("/1")
app.deploy do
expect(app.output).to include("Installing JDK #{openjdk_version}")
expect(app.output).to include("BUILD SUCCESS")
expect(app.output).not_to include("BUILD FAILURE")
expect(http_get(app)).to eq("/1")

expect(app.run('echo $JAVA_OPTS')).
to include(%q{-Xmx300m -Xss512k})
expect(app.run("echo $JAVA_OPTS"))
Malax marked this conversation as resolved.
Show resolved Hide resolved
.to include("-Xmx300m -Xss512k")

expect(app.run("env", { :heroku => { "exit-code" => Hatchet::App::SkipDefaultOption }})). # work around a CLI bug that doesn't allow --exit-code when invoking a process type via "heroku run"
not_to include(%q{DATABASE_URL})
expect(app.run("env"))
.not_to include("DATABASE_URL")

expect(app.run("jce", { :heroku => { "exit-code" => Hatchet::App::SkipDefaultOption }})). # work around a CLI bug that doesn't allow --exit-code when invoking a process type via "heroku run"
to include(%q{Encrypting, "Test"}).
and include(%q{Decrypted: Test})
expect(app.run("java -cp target/app.jar JCE"))
.to include("Encrypting, \"Test\"")
.and include("Decrypted: Test")

expect(app.run("netpatch", { :heroku => { "exit-code" => Hatchet::App::SkipDefaultOption }})). # work around a CLI bug that doesn't allow --exit-code when invoking a process type via "heroku run"
to include(%q{name:eth0 (eth0)}).
and include(%q{name:lo (lo)})
expect(app.run("java -cp target/app.jar NetPatch"))
.to include("name:eth0 (eth0)")
.and include("name:lo (lo)")

expect(app.run("https", { :heroku => { "exit-code" => Hatchet::App::SkipDefaultOption }})). # work around a CLI bug that doesn't allow --exit-code when invoking a process type via "heroku run"
to include("Successfully invoked HTTPS service.").
and match(%r{"X-Forwarded-Proto(col)?":\s?"https"})
expect(app.run("java -cp target/app.jar Https"))
.to include("Successfully invoked HTTPS service.")
.and match(%r{"X-Forwarded-Proto(col)?":\s?"https"})

# JDK 9, 10, 11 and beyond do not have the jre/lib/ext dir where we drop the pgconfig.jar
if jdk_version.match(/^(1\.7|1\.8|7|8)$/)
expect(app.run("pgssl", { :heroku => { "exit-code" => Hatchet::App::SkipDefaultOption }})). # work around a CLI bug that doesn't allow --exit-code when invoking a process type via "heroku run"
to include("sslmode: require")
end
# OpenJDK versions > 9 do not have the jre/lib/ext directory where we drop the pgconfig.jar
if openjdk_version.match(%r{^(1\.7|1\.8)$})
expect(app.run("java -cp target/app.jar PostgresSSLTest"))
.to include("sslmode: require")
end
end
end
end
end
end

%w{1.7 1.8}.each do |jdk_version|
context "#{jdk_version} with webapp-runner" do
context "and expanded war" do
it "expands war", :retry => 3, :retry_wait => 5 do
Hatchet::Runner.new("webapp-runner-sample").tap do |app|
app.before_deploy do
set_java_version(Dir.pwd, jdk_version)

File.open('Procfile', 'w') do |f|
f.puts <<-EOF
web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --expand-war --port $PORT target/*.war
EOF
end
`git commit -am "adding --expand-war to Procfile"`
end

app.deploy
expect_successful_maven(app, jdk_version)
expect(app.output).to match(%r{Building war: /tmp/.*/target/.*.war})
expect(app.output).not_to match(%r{Building jar: /tmp/.*/target/.*.jar})
it "work correctly when libpng dependent features are used" do
Hatchet::Runner.new("libpng-test", stack: ENV["HEROKU_TEST_STACK"]).tap do |app|
app.before_deploy do
set_java_version(openjdk_version)
end

expect(successful_body(app)).to eq("Hello from Java!")
end
app.deploy do
expect(app.output).to include("Installing JDK #{openjdk_version}")
expect(app.output).to include("BUILD SUCCESS")
expect(app.output).not_to include("BUILD FAILURE")
expect(http_get(app)).to eq("All Good!!!")
end
end
end
end

%w{1.8 11 13 15}.each do |jdk_version|
context "#{jdk_version} libpng test" do
it "returns a successful response", :retry => 3, :retry_wait => 5 do
Hatchet::Runner.new("libpng-test").tap do |app|
it "works correctly with --expand-war option on webapp-runner" do
Hatchet::Runner.new("webapp-runner-sample").tap do |app|
app.before_deploy do
set_java_version(Dir.pwd, jdk_version)
set_java_version(openjdk_version)
write_to_procfile("web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --expand-war --port $PORT target/*.war")
end

app.deploy do |app|
expect_successful_maven(app, jdk_version)
expect(successful_body(app)).to eq("All Good!!!")
app.deploy do
expect(app.output).to include("Installing JDK #{openjdk_version}")
expect(app.output).to include("BUILD SUCCESS")
expect(app.output).not_to include("BUILD FAILURE")

expect(app.output).to match(%r{Building war: /tmp/.*/target/.*.war})
expect(app.output).not_to match(%r{Building jar: /tmp/.*/target/.*.jar})

expect(http_get(app)).to eq("Hello from Java!")
end
end
end
Expand Down
Loading