This page describes an older version of the product. The latest stable version is 16.4.

JUnit Testing

When creating unit tests with XAP you will use an Embedded Space 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 XAP 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) { = id;
    public Long getCategory() {
        return category;
    public void setCategory(Long category) {
        this.category = category;
    public String getName() {
        return name;
    public void setName(String name) { = name;
<beans xmlns=""
    xmlns:xsi="" xmlns:context=""
    xmlns:os-core="" xmlns:os-jms=""
    xmlns:os-sla="" xmlns:tx=""

    <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 routing 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>