jruby Rails memcached 与 java 类的解组错误

发布于 2024-08-17 11:33:12 字数 1898 浏览 8 评论 0原文

我有一个 Rails 应用程序,它通过 JMS 与一些 Java 服务进行通信。我在 Rails 端的 memcached 中缓存了其中一些对象,如下所示:

@my_objects = MEMCACHE["some_key"] || @service.retrieve_objects
MEMCACHE.set("some_key",@my_objects) if MEMCACHE["some_key"].nil?

MEMCACHE

MEMCACHE = MemCache.new(['localhost'], :namespace=>"namespace-#{RAILS_ENV}")

现在,我正在尝试编写测试来验证我的 memcache 是否正确存储了这些对象并正确更新。不幸的是,当我尝试访问缓存中的对象时,我得到

MemCache::MemCacheError: Class not found unmarshaling Java type: my/java/package/Classname

奇怪的是,在脚本/控制台中引用缓​​存工作正常。然而,当我运行应用程序和单元测试时,我收到此错误。我认为在同一环境中控制台和应用程序之间没有任何区别。

我在下面包含了完整的堆栈跟踪。它似乎来自 ActiveSupports Memcache 客户端的深处。我已经尝试了所有的组合,甚至在访问缓存之前实例化这个特定的类,但都不起作用。

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_17) [x86_64-java]
Rails 2.2.2
OSX 10.6

完整测试堆栈跟踪

  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'

I have a rails app that is communicating with some java services over JMS. I'm caching a few of these objects in memcached on the rails side like so:

@my_objects = MEMCACHE["some_key"] || @service.retrieve_objects
MEMCACHE.set("some_key",@my_objects) if MEMCACHE["some_key"].nil?

where MEMCACHE is

MEMCACHE = MemCache.new(['localhost'], :namespace=>"namespace-#{RAILS_ENV}")

Now, I'm trying to write tests to verify that my memcache is storing these properly and updating properly. Unfortunately when I try to access the objects in the cache I get

MemCache::MemCacheError: Class not found unmarshaling Java type: my/java/package/Classname

What's odd is that referencing the cache in script/console works fine. When I run the app and my unit tests however, I get this error. I didn't think there was any difference between the console and the app when in the same env.

I've included the full stack trace below. It appears to come from deep down in ActiveSupports Memcache client. I've tried all combination of things, even instantiating this particular class right before accessing the cache, but none of it works.

Rails obviously knows about the class as I can retrieve, instantiate and create these java objects directly in my test with no problems, it's only when accessing it from MEMCACHE that I get this error.

Setup
jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-13 6586) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_17) [x86_64-java]
Rails 2.2.2
OSX 10.6

Full test stack trace

  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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文