I was talking to Shay Banon (Gigaspace Software Architect) he mentioned using GigaSpaceFactoryBean for writing gigaspace unit tests. I could find no examples on their site, although I concede it may be there somewhere. This shows post shows a simple example.
He also mentioned using the admin api to do full end to end integration testing. The admin api has huge potential as its able to control gigaspace containers, deploy into them and collect statistics. Its a powerful api.
This is documented on their site: http://www.gigaspaces.com/wiki/display/XAP7/Administration+and+Monitoring+API
Example unit test using GigaSpaceFactoryBean
The GigaSpaceFactoryBean does have javadoc: http://www.gigaspaces.com/docs/JavaDoc7.1/index.html. It can be used to provide a unit test with a gigaspace implementation for the duration of the test.
Step 1 Provide a spring definition of the GigaSpaceFactoryBean
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:os-core="http://www.openspaces.org/schema/core" xmlns:os-events="http://www.openspaces.org/schema/events" xmlns:os-remoting="http://www.openspaces.org/schema/remoting" xmlns:os-sla="http://www.openspaces.org/schema/sla" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.openspaces.org/schema/core http://www.openspaces.org/schema/core/openspaces-core.xsd http://www.openspaces.org/schema/events http://www.openspaces.org/schema/events/openspaces-events.xsd http://www.openspaces.org/schema/remoting http://www.openspaces.org/schema/remoting/openspaces-remoting.xsd http://www.openspaces.org/schema/sla http://www.openspaces.org/schema/sla/openspaces-sla.xsd"> <os-core:local-tx-manager id="gs.transactionManager" space="testGigaSpace" default-timeout="1000" /> <os-core:space id="testGigaSpace" url="/./my-test-pu" /> <bean id="gigaSpace"> <property name="space" ref="testGigaSpace" /> <property name="transactionManager" ref="gs.transactionManager" /> </bean>
Follow with other beans needed by the test. I.e service beans and their dependencies. Note that the space defined here will also need to be injected into services that need it. So you will need to use the same bean id. Careful separation of the spring files means you will be able to substitute a test space for the real one during testing.
Step 2 Write a unit test
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/somewhere/sometest-pu.xml")
public class SomeGigaspaceTest {
@Resource
private ServiceUnderTest myservice;
@Resource
private GigaSpace gigaSpace;
@Before
public void setUp() {
// Setup anything you may wish to be
// in the space before the test starts.
this.gigaSpace.write(stuff);
}
@Test
public void testSomething() throws InterruptedException {
ImmutableSet dataFromGS = this.myservice.getStuff();
assertFalse(dataFromGS.isEmpty());
assertThat(dataFromGS.size(), is(100));
}












