JUnit Testing

When creating unit tests with data grid you will use an Embedded SpaceClosed Where GigaSpaces data is stored. It is the logical cache that holds data objects in memory and might also hold them in layered in tiering. Data is hosted from multiple SoRs, consolidated as a unified data model. that is internally represented by the IntegratedProcessingUnitContainer class and a reference to this Space will be available through a class implementing the GigaSpace interface. This allows you to read / write objects to that Space just as you normally would in any data grid application.

Simple test

Here is an example of a simple JUnit test:

public class SpaceData {
    private UUID id;
    private Long category;
    private String name;

    public UUID getId() {
        return id;
    public void setId(UUID id) {
        this.id = id;
    public Long getCategory() {
        return category;
    public void setCategory(Long category) {
        this.category = category;
    public String getName() {
        return name;
    public void setName(String name) {
        this.name = name;
<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-jms="http://www.openspaces.org/schema/jms"
    xmlns:os-sla="http://www.openspaces.org/schema/sla" xmlns:tx="http://www.springframework.org/schema/tx"
    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.openspaces.org/schema/core http://www.openspaces.org/schema/17.0.0/core/openspaces-core.xsd
    http://www.openspaces.org/schema/events http://www.openspaces.org/schema/17.0.0/events/openspaces-events.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.openspaces.org/schema/remoting http://www.openspaces.org/schema/17.0.0/remoting/openspaces-remoting.xsd">

    <os-core:embedded-space id="aSpace" space-name="processingSpace" />

    <os-core:giga-space id="processingSpace" space="aSpace" />


And here is the JUnit test case

@ContextConfiguration(locations = { "classpath:META-INF/application-context.xml" })
public class TestXAP {

    private GigaSpace processingSpace;

    public void simpleUnitTest() {

        SpaceData data = new SpaceData();
        data.setName("Test data");


        SQLQuery<SpaceData> query = new SQLQuery<SpaceData>(SpaceData.class, "");
        SpaceData[] result = processingSpace.readMultiple(query);

        Assert.assertEquals(result.length, 1);

    public void init() {

Partition/Routing test

Testing partitioning and routingClosed The mechanism that is in charge of routing the objects into and out of the corresponding partitions. The routing is based on a designated attribute inside the objects that are written to the Space, called the Routing Index. can be accomplished by using the IntegratedProcessingUnitContainerProvider. You can start multiple partitions by defining with the ClusterInfo the number of members of a cluster.

In the example below 4 partitions are started.

public class ClusterTest {

    private GigaSpace space;

    public void testCluster() {

        for (int i = 0; i < 4; i++) {
            SpaceData data = new SpaceData();
            data.setName("Space Data " + i);
            data.setCategory(new Long(i));


        SQLQuery<SpaceData> query = new SQLQuery<SpaceData>(SpaceData.class, "");
        SpaceData[] result = space.readMultiple(query);

        Assert.assertEquals(result.length, 4);

    public void init() {
            IntegratedProcessingUnitContainerProvider provider = new IntegratedProcessingUnitContainerProvider();
            ClusterInfo clusterInfo = new ClusterInfo();

            ProcessingUnitContainer c = provider.createContainer();

            space = new GigaSpaceConfigurer(new SpaceProxyConfigurer("processingSpace")).gigaSpace();

You can verify that the 4 partitions exists by starting the Management Center

Lookup Service

The StandaloneProcessingUnitContainer automatically starts an embedded Lookup service. If you intend to use a separate Lookup service you can disable the embedded Lookup service by passing the setting the com.j_spaces.core.container.directory_services.jini_lus.enabled system property to false. This property can also be set within the Space definition:

<os-core:embedded-space id="space" space-name="mySpace">
        <prop key="com.j_spaces.core.container.directory_services.jini_lus.start-embedded-lus">false</prop>