Skip to content

Instantly share code, notes, and snippets.

@takeru
Created April 19, 2010 17:58
Show Gist options
  • Select an option

  • Save takeru/371362 to your computer and use it in GitHub Desktop.

Select an option

Save takeru/371362 to your computer and use it in GitHub Desktop.
tkrmb:~/tmp/gae_jruby_20100420_015717% VERBOSE=1 LANG=C appcfg.rb run -S irb
"java" "-Dfile.encoding=UTF-8" "-cp" "/Users/takeru/tmp/gae_jruby_20100420_015717/WEB-INF/lib/appengine-api-1.0-sdk-1.3.2.jar:/Users/takeru/tmp/gae_jruby_20100420_015717/WEB-INF/lib/appengine-api-labs-1.3.2.jar:/Users/takeru/tmp/gae_jruby_20100420_015717/WEB-INF/lib/appengine-jruby-0.0.7.pre.jar:/Users/takeru/tmp/gae_jruby_20100420_015717/WEB-INF/lib/gems.jar:/Users/takeru/tmp/gae_jruby_20100420_015717/WEB-INF/lib/jruby-rack-0.9.7.jar:/opt/local/lib/ruby/gems/1.8/gems/appengine-sdk-1.3.2/appengine-java-sdk-1.3.2/lib/shared/appengine-local-runtime-shared.jar:/opt/local/lib/ruby/gems/1.8/gems/appengine-sdk-1.3.2/appengine-java-sdk-1.3.2/lib/impl/appengine-api-stubs.jar:/opt/local/lib/ruby/gems/1.8/gems/appengine-sdk-1.3.2/appengine-java-sdk-1.3.2/lib/impl/appengine-local-runtime.jar:/opt/local/lib/ruby/gems/1.8/gems/appengine-sdk-1.3.2/appengine-java-sdk-1.3.2/lib/testing/appengine-testing.jar" "org.jruby.Main" "-rappengine_boot" "-S" "irb"
Apr 20, 2010 12:46:18 PM com.google.appengine.api.datastore.dev.LocalDatastoreService load
INFO: The backing store, /Users/takeru/tmp/gae_jruby_20100420_015717/./WEB-INF/appengine-generated/local_db.bin, does not exist. It will be created.
Apr 20, 2010 12:46:18 PM com.google.appengine.api.datastore.dev.LocalDatastoreService load
INFO: The backing store, /Users/takeru/tmp/gae_jruby_20100420_015717/./WEB-INF/appengine-generated/local_db.bin, does not exist. It will be created.
Apr 20, 2010 12:46:18 PM com.google.appengine.api.labs.taskqueue.dev.LocalTaskQueue init
INFO: LocalTaskQueue is initialized
Apr 20, 2010 12:46:18 PM com.google.appengine.api.labs.taskqueue.dev.LocalTaskQueue init
INFO: Automatic task execution is disabled.
Apr 20, 2010 12:46:18 PM org.quartz.simpl.SimpleThreadPool initialize
INFO: Job execution threads will use class loader of thread: main
Apr 20, 2010 12:46:18 PM org.quartz.core.QuartzScheduler <init>
INFO: Quartz Scheduler v.UNKNOWN.UNKNOWN.UNKNOWN created.
Apr 20, 2010 12:46:18 PM org.quartz.simpl.RAMJobStore initialize
INFO: RAMJobStore initialized.
Apr 20, 2010 12:46:18 PM org.quartz.impl.StdSchedulerFactory instantiate
INFO: Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties'
Apr 20, 2010 12:46:18 PM org.quartz.impl.StdSchedulerFactory instantiate
INFO: Quartz scheduler version: UNKNOWN.UNKNOWN.UNKNOWN
Apr 20, 2010 12:46:18 PM com.google.appengine.api.labs.taskqueue.dev.LocalTaskQueue start_
INFO: Local task queue initialized with base url http://localhost:8080
Apr 20, 2010 12:46:18 PM com.google.appengine.api.labs.taskqueue.dev.LocalTaskQueue start_
INFO: Local task queue initialized with base url http://localhost:8080
irb(main):001:0> puts "hello"
hello
=> nil
irb(main):002:0> exit
Apr 20, 2010 12:46:30 PM org.quartz.core.QuartzScheduler shutdown
INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutting down.
Apr 20, 2010 12:46:30 PM org.quartz.core.QuartzScheduler standby
INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED paused.
Apr 20, 2010 12:46:30 PM org.quartz.core.QuartzScheduler shutdown
INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutdown complete.
tkrmb:~/tmp/gae_jruby_20100420_015717%
=begin
hand patch to lib/appengine-apis/testing.rb
(1)
configs = nil if ENV['SKIP_LOCAL_SERVICE_APIS']
(2)
def boot
# if delegate
# return
# end
# self.persistent_datastore = true
# setup
end
run this script:
SKIP_LOCAL_SERVICE_APIS=1 VERBOSE=1 LANG=C appcfg.rb run local_test.rb
=end
testing = Java::ComGoogleAppengineToolsDevelopmentTesting
configs = [
testing::LocalDatastoreServiceTestConfig.new,
testing::LocalBlobstoreServiceTestConfig.new,
testing::LocalTaskQueueTestConfig.new,
testing::LocalImagesServiceTestConfig.new,
testing::LocalMailServiceTestConfig.new,
testing::LocalMemcacheServiceTestConfig.new,
testing::LocalURLFetchServiceTestConfig.new,
testing::LocalUserServiceTestConfig.new,
testing::LocalXMPPServiceTestConfig.new,
].to_java(testing::LocalServiceTestConfig)
puts "***** before helper."
helper = testing::LocalServiceTestHelper.new(configs)
puts "***** after helper."
puts "***** before setUp."
helper.setUp
puts "***** after setUp."
if true
puts "***** before svc start/stop."
ds_svc = testing::LocalDatastoreServiceTestConfig.getLocalDatastoreService
bs_svc = testing::LocalBlobstoreServiceTestConfig.getLocalBlobstoreService
tq_svc = testing::LocalTaskQueueTestConfig.getLocalTaskQueue
ds_svc.start
bs_svc.start
tq_svc.start
tq_svc.stop
bs_svc.stop
ds_svc.stop
puts "***** after svc start/stop."
end
puts "***** before tearDown."
helper.tearDown
puts "***** after tearDown."
#testing::LocalServiceTestHelper.getApiProxyLocal.stop
if false
require "pp"
java.lang.Thread.getAllStackTraces.each{|a,b|
puts "="*80
p a
pp b.collect{|c| c }
}
puts "="*80
end
#!/usr/bin/ruby1.8 -w
#
# Copyright:: Copyright 2009 Google Inc.
# Original Author:: Ryan Brown (mailto:ribrdb@google.com)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Helpers for installing stub apis in unit tests.
module AppEngine
# Local testing support for Google App Engine
#
# If you run your code on Google's servers or under dev_appserver,
# the api's are already configured.
#
# To run outside this environment, you need to install a test environment and
# api stubs.
module Testing
class << self
def delegate # :nodoc:
helper # make sure everything's loaded
require 'appengine-apis/apiproxy'
AppEngine::ApiProxy.getDelegate
end
# The LocalServiceTestHelper used by this class.
# Use this to set the logged in user, etc.
def helper
failed = false
@helper ||= begin
testing = Java::ComGoogleAppengineToolsDevelopmentTesting
@datastore_config = testing::LocalDatastoreServiceTestConfig.new
configs = [
@datastore_config,
testing::LocalBlobstoreServiceTestConfig.new,
testing::LocalImagesServiceTestConfig.new,
testing::LocalMailServiceTestConfig.new,
testing::LocalMemcacheServiceTestConfig.new,
testing::LocalTaskQueueTestConfig.new,
testing::LocalURLFetchServiceTestConfig.new,
testing::LocalUserServiceTestConfig.new,
testing::LocalXMPPServiceTestConfig.new,
].to_java(testing::LocalServiceTestConfig)
testing::LocalServiceTestHelper.new(configs)
rescue => ex
if failed
raise ex
else
failed = true
require 'appengine-sdk'
AppEngine::SDK.load_local_test_helper
retry
end
end
end
# Install stub apis and force all datastore operations to use
# an in-memory datastore.
#
# You may call this multiple times to reset to a new in-memory datastore.
def install_test_datastore
self.persistent_datastore = false
setup
end
def persistent_datastore
helper
!@datastore_config.is_no_storage
end
def persistent_datastore=(value)
helper
@datastore_config.set_no_storage(!value)
setup
end
def setup
unless @active
if delegate
teardown rescue nil
end
helper.setUp
testing = Java::ComGoogleAppengineToolsDevelopmentTesting
@api_proxy_local = testing::LocalServiceTestHelper.getApiProxyLocal
@services = [com.google.appengine.api.datastore.dev.LocalDatastoreService,
com.google.appengine.api.labs.taskqueue.dev.LocalTaskQueue,
com.google.appengine.api.blobstore.dev.LocalBlobstoreService
].collect do |service_class|
@api_proxy_local.getService(service_class::PACKAGE)
end
@services.each{|svc| svc.start }
@active = true
true
else
false
end
end
def teardown
if @active
@services.each{|svc| svc.stop }
@services = nil
AppEngine::ApiProxy.setDelegate(@api_proxy_local)
@api_proxy_local = nil
helper.tearDown
@active = false
true
else
false
end
end
at_exit{
AppEngine::Testing.teardown
}
# Loads stub API implementations if no API implementation is
# currently configured.
#
# Sets up a datastore saved to disk in '.'.
#
# Does nothing is APIs are already configured (e.g. in production).
#
# As a shortcut you can use
# require 'appengine-apis/local_boot'
#
def boot
if delegate
return
end
self.persistent_datastore = true
setup
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment