Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

Question about JUnit

I found a useful post here about testing and gigaspace. But when I try to reproduce this I always get an exception:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'postServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'gigaSpace' must be of type org.openspaces.core.GigaSpace, but was actually of type com.gigaspaces.internal.client.spaceproxy.SpaceProxyImpl
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
    at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)
... 30 more

As I see the problem is in using of JDK proxies, but <aop:config proxy-target-class="true" > doesn't solve my problem. Any idea about this?

This thread was imported from the previous forum.
For your reference, the original is available here

asked 2012-12-02 09:24:16 -0500

afrunt gravatar image

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

Are you sure you are injecting os-core:giga-space into a GigaSpace object annotated with @GigaSpaceContext?

Hows your pu.xml and code looks like?

answered 2012-12-02 09:29:45 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Comments

pu.xml

http://www.springframework.org/schema... http://www.openspaces.org/schema/corehttp://www.openspaces.org/schema/core...http://www.springframework.org/schema...http://www.springframework.org/schema...http://www.openspaces.org/schema/remo...http://www.openspaces.org/schema/8.0/...http://www.springframework.org/schema...http://www.springframework.org/schema...>

<context:annotation-config/>
<context:component-scan base-package="com.exadel.gs"/>

<os-core:annotation-support/>
<os-core:space id="gigaSpace" url="/./test-space"/>
<os-core:local-tx-manager id="gs.transactionManager" space="gigaSpace" default-timeout="1000"/>
<os-remoting:annotation-support/>
<os-remoting:service-exporter id="serviceExporter"/>
<!--Factory bean for starting GigaSpaces context during test phase-->
<bean id="testSpaceFactoryBean" class="org.openspaces.core.GigaSpaceFactoryBean">
    <property name="space" ref="gigaSpace"/>
    <property name="transactionManager" ref="gs.transactionManager"/>
</bean>

</beans>

@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "/META-INF/spring/pu.xml") public class SomeTest { @ExecutorProxy private PostService postService; @GigaSpaceContext private GigaSpace gigaSpace;

@test
public void test(){
    System.out.println("GigaSpace="+gigaSpace);
    Post post = new Post();
    post.setId(1L);
    post.setDate(new Date());
    post.setText("text");
    post.setUsername("username");
    postService.submitPost(post);
    Assert.assertEquals("There should be only one post in space", 1, gigaSpace.count(new Post()));
    postService.removePost(post);
    Assert.assertEquals("There should be no posts in space", 0, gigaSpace.count(new Post()));
}

}

@RemotingService public class PostServiceImpl implements PostService { @GigaSpaceContext private GigaSpace gigaSpace;

@Override
public void submitPost(Post post) {
    gigaSpace.write(post);
}

@Override
public void removePost(Post post) {
    gigaSpace.take(post);
}

}

In this case I see that gigaSpace=null

Edited by: Andrey Frunt on Dec 2, 2012 9:50 AM

afrunt gravatar imageafrunt ( 2012-12-02 09:39:41 -0500 )edit

replace: <os-core:space id="gigaSpace" url="/./test-space"/> with this: <os-core:space id="space" url="/./test-space"/>

replace: <property name="space" ref="gigaSpace"/> with <property name="gigaSpace" ref="gigaSpace"/>

replace: <os-core:local-tx-manager id="gs.transactionManager" space="gigaSpace" default-timeout="1000"/> with <os-core:local-tx-manager id="gs.transactionManager" space="space" default-timeout="1000"/>

and add: <os-core:giga-space id="gigaSpace" space="space"/>

Shay

Edited by: Shay Hassidim on Dec 2, 2012 10:47 AM

shay hassidim gravatar imageshay hassidim ( 2012-12-02 10:45:54 -0500 )edit

Thanks! Looks better now but fails with the next error. {code} Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@10e0eb5] to prepare test instance [com.exadel.test.space.test.SomeTest@1e7c609]; Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'No GigaSpaces name given and factory contains several' is defined {code}

I tried to like below but it doesn't change anything

{code} @GigaSpaceContext(name = "gigaSpace") private GigaSpace gigaSpace; {code}

Now my PU looks like below: {code:xml} http://www.springframework.org/schema... http://www.openspaces.org/schema/corehttp://www.openspaces.org/schema/core...http://www.springframework.org/schema...http://www.springframework.org/schema...http://www.openspaces.org/schema/remo...http://www.openspaces.org/schema/8.0/...http://www.springframework.org/schema...http://www.springframework.org/schema...>

<context:annotation-config/>
<context:component-scan base-package="com.exadel.gs"/>

<os-core:annotation-support/>

<os-core:space id="space" url="/./test-space"/>
<os-core:giga-space id="gigaSpace" space="space"/>

<os-core:local-tx-manager id="gs.transactionManager" space="space" default-timeout="1000"/>

<os-remoting:annotation-support/>

<os-remoting:service-exporter id="serviceExporter"/>
<!--Factory bean for starting GigaSpaces context during test phase-->
<bean id="testSpaceFactoryBean" class="org.openspaces.core.GigaSpaceFactoryBean">
    <property name="space" ref="space"/>
    <property name="transactionManager" ref="gs.transactionManager"/>
</bean>

</beans> {code}

Edited by: Andrey Frunt on Dec 2, 2012 12:22 PM

Edited by: Andrey Frunt on Dec 2, 2012 12:24 PM

afrunt gravatar imageafrunt ( 2012-12-02 12:17:25 -0500 )edit

Any idea why it so?

afrunt gravatar imageafrunt ( 2012-12-03 02:41:31 -0500 )edit

why you need testSpaceFactoryBean? I believe you should remove it.

shay hassidim gravatar imageshay hassidim ( 2012-12-03 05:02:35 -0500 )edit
0

I used a slightly different approach, I define a pu.xml specifically for a test class (here "collectortasktest-pu.xml") and tell the provider (with provider.addConfigLocation(..) ) to use that before creating the container in the test class:

IntegratedProcessingUnitContainerProvider provider = new IntegratedProcessingUnitContainerProvider();
provider.addConfigLocation("classpath:/META-INF/spring/collectortasktest-pu.xml");

And that was all that I needed. So I can define a pu.xml for each test class.

answered 2013-09-19 03:10:55 -0500

djw gravatar image
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-12-02 09:24:16 -0500

Seen: 462 times

Last updated: Sep 19 '13