2016-12-02 12 views
1

私はjclouds 2.0.0に移行しました(反復可能な操作ではない問題のいくつかを想定していました。ここに依存関係があります。jcloudsとOpenstack Swiftでの単体テストの一時的なモード

<dependency> 
     <groupId>org.apache.jclouds.driver</groupId> 
     <artifactId>jclouds-slf4j</artifactId> 
     <version>2.0.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.jclouds.api</groupId> 
     <artifactId>openstack-keystone</artifactId> 
     <version>2.0.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.jclouds.api</groupId> 
     <artifactId>openstack-swift</artifactId> 
     <version>2.0.0</version> 
    </dependency> 

私のコードの単体テストが必要です。私はプロバイダとしてtransientを使用する場合でも:

SwiftApi swiftApi = ContextBuilder.newBuilder("transient") 
       .endpoint(endpoint) 
       .credentials(user, password) 
       .modules(modules) 
       .overrides(overrides) 
       .buildApi(SwiftApi.class); 

私はこの例外を取得:

com.google.inject.ConfigurationException: Guice configuration errors: 

1) No implementation for org.jclouds.openstack.swift.v1.SwiftApi was bound. 
    while locating org.jclouds.openstack.swift.v1.SwiftApi 

1 error 

    at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1004) 
    at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1009) 
    at org.jclouds.ContextBuilder.buildApi(ContextBuilder.java:651) 
    at org.jclouds.ContextBuilder.buildApi(ContextBuilder.java:643) 
    at eu.europeana.cloud.service.mcs.persistent.swift.SimpleSwiftConnectionProvider.openConnections(SimpleSwiftConnectionProvider.java:91) 
    at eu.europeana.cloud.service.mcs.persistent.swift.SimpleSwiftConnectionProvider.<init>(SimpleSwiftConnectionProvider.java:67) 
    at eu.europeana.cloud.service.mcs.persistent.swift.SimpleSwiftConnectionProviderTest.getContainer(SimpleSwiftConnectionProviderTest.java:24) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137) 
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) 
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) 
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237) 
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) 

プロバイダとしてopenstack-swiftと同じコードの実行(および正しい資格情報とエンドポイント)がうまく動作します。 はnewBuilder関数のパラメータの原因として他の文字列を渡す:

私は transientがサポートされるべきであると考えさせ
java.util.NoSuchElementException: key [wrongstring] not in the list of providers or apis: {apis=[openstack-keystone, openstack-swift, transient]} 
    at org.jclouds.ContextBuilder.newBuilder(ContextBuilder.java:175) 

。しかし、それを動作させる方法は?

答えて

0

一時的なブロブストアのビューをSwiftApi作成することはできません。

String provider = ...; // openstack-swift or transient 
BlobStoreContext context = ContextBuilder.newBuilder(provider) 
      .endpoint(endpoint) 
      .credentials(user, password) 
      .buildApi(BlobStoreContext.class); 
BlobStore blobStore = context.getBlobStore(); 
// interact with blobStore, e.g., get, put 
... 
context.close(); 
+0

私は最後にやったことだし、それが動作します...しかし、最初に、それはあなたがユニットテストSwiftApiコードではないことを、少し悲しいです:代わりに、あなたは、ポータブルBlobStoreビューを使用する必要があります。そして2番目:利用可能なプロバイダをリストアップすることは間違っていて、誤解を招くことです。 – lotk

+0

SwiftApiとtransientは異なるAPIを持っているため、一方をもう一方のプラグインにすることはできません。 BlobStoreコードは、このポータブルレイヤーを実装しています。 SwiftProxyを使用するには、Swiftサーバーをテストする必要があります。https://github.com/bouncestorage/swiftproxy –

+0

ご清聴ありがとうございます。 BlobstoreよりSwiftApiを使用する利点はありますか?私はjclouds v2よりも前に使用していましたが、現在は完全に正常に動作していますが、ドキュメントではSwiftApiを使用することが推奨されています:https://jclouds.apache.org/guides/openstack/#swift 私はそれを考慮する必要がありますか? – lotk

関連する問題