我有一个rails应用程序,它通过JMS与一些java服务通信。我将其中一些对象缓存在memcached的rails端,如下所示:
@my_objects = MEMCACHE["some_key"] || @service.retrieve_objects
MEMCACHE.set("some_key",@my_objects) if MEMCACHE["some_key"].nil?
MEMCACHE = MemCache.new(['localhost'], :namespace=>"namespace-#{RAILS_ENV}")
现在,我正在尝试编写测试来验证我的memcache是否正确地存储和更新了这些内容。不幸的是,当我试图访问缓存中的对象时
MemCache::MemCacheError: Class not found unmarshaling Java type: my/java/package/Classname
奇怪的是,在脚本/控制台中引用缓存可以正常工作。但是,当我运行应用程序和单元测试时,我得到了这个错误。我不认为控制台和应用程序在同一个环境中有什么区别。
Rails显然知道这个类,因为我可以在测试中直接检索、实例化和创建这些java对象,而没有任何问题,只有从MEMCACHE访问它时,我才会出现这个错误。
安装程序
jruby 1.4.0(ruby 1.8.7 patchlevel 174)(2009-11-13 6586)(Java HotSpot(TM)64位服务器VM 1.6.0_)[x86_64-Java]
完整测试堆栈跟踪
1) Error:
test_testing_memcache_and_settings(MyTest):
MemCache::MemCacheError: Class not found unmarshaling Java type: my/java/package/Classname
/opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb:241:in `marshal_load'
/opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb:241:in `load'
/opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb:241:in `get'
./test/unit/my_test.rb:54:in `test_testing_memcache_and_settings'
/opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/testing/setup_and_teardown.rb:60:in `run_with_callbacks_and_testunit'