Skip to content

GS-Test is a set of utilities designed to simplify unit testing of applications implemented using GigaSpaces

Notifications You must be signed in to change notification settings

AvanzaBank/gs-test

Repository files navigation

Deprecated

This project is no longer publicly maintained. It will receive no more updates and will eventually be removed.


GS-Test

Average time to resolve an issue Percentage of issues still open

The GS-Test library contains utilities designed to simplify testing of applications implemented using GigaSpaces.

Running an embedded Processing Unit

The PuConfigurers/StandalonePuConfigurers classes contains factory methods for builders for different types of processing units (partitioned pu, mirror pu). Those can be used to create an embedded processing unit (RunningPu). The RunningPu is available as a @TestRule for JUnit4 and as an Extension for JUnit5.

Example: Using JUnit4 @Rule and RunningPu to start/stop a pu around each test case
class FruitTest {
  @Rule
  public RunningPu fruitPu = PuConfigurers.partitionedPu("classpath:/fruit-pu.xml")
                                          .configure();
                                   
  // Test cases against fruitPu
}
Example: Using JUnit5 @RegisterExtension to start/stop a pu around each test case
class FruitTest {
  @RegisterExtension
  public RunningPu fruitPu = PuConfigurers.partitionedPu("classpath:/fruit-pu.xml")
                                          .configure();
                                   
  // Test cases against fruitPu
}
Example: Starting/stopping a Pu explicitly, without any test framework
class FruitTest {

  StandaloneRunningPu fruitPu = StandalonePuConfigurers.partitionedPu("classpath:/fruit-pu.xml")
                                                       .configure();
  
  @Before                                 
  public void startFruitPu() {
      fruitPu.start();
  }

	@After
	public void stopFruitPu() {
		fruitPu.stop();
	}

	// Test cases against fruitPu
}

Running an Embedded Gigaspace

In case you only need access to gigaspace, you can use the EmbeddedSpace as a @Rule in Junit 4 or as an @ExtendWith for Junit 5:

Example: Using Junit4 @Rule to get an embedded Gigaspace instance
public class EmbeddedSpaceAsRuleTest {

	@Rule
	public final EmbeddedSpace embeddedSpace = new EmbeddedSpace("space-name");

	@Test
	public void testPersistingAndReading() {
		GigaSpace gigaSpace = embeddedSpace.getGigaSpace();
		gigaSpace.write(new FruitPojo("orange"));

		FruitPojo fruit = gigaSpace.readById(FruitPojo.class, "orange");
		assertNotNull(fruit);
	}
}
Example: Using Junit 5 @ExtendWith to get EmbeddedSpace instance
@ExtendWith(EmbeddedSpace.class)
class GigaspaceExtensionTest {

	@Test
	void testPersistingAndReading(GigaSpace gigaSpace) {
		gigaSpace.write(new FruitPojo("orange"));

		FruitPojo fruit = gigaSpace.readById(FruitPojo.class, "orange");
		assertNotNull(fruit);
	}
}

ZooKeeper

Since version 2.1.0 this library comes bundled with ZooKeeper, and switches to using a ZooKeeper based leader selector for GigaSpaces.

In order to run tests without ZooKeeper, run the tests with system property -Dcom.avanza.gs.test.zookeeper.disable=true. In this case, a LUS-based selector will be used.

Maven

Core

The core module that contains standalone configuration, without depending on any testing framework.

<dependency>
  <groupId>com.avanza.gs</groupId>
  <artifactId>gs-test-core</artifactId>
  <version>2.1.x</version>
</dependency>

JUnit4

JUnit4 bindings for running as test rules.

<dependency>
  <groupId>com.avanza.gs</groupId>
  <artifactId>gs-test-junit4</artifactId>
  <version>2.1.x</version>
</dependency>

This artifact replaces com.avanza.gs:gs-test from pre-2.1.0 versions of this library.

JUnit5

JUnit5 extension bindings.

<dependency>
  <groupId>com.avanza.gs</groupId>
  <artifactId>gs-test-junit5</artifactId>
  <version>2.1.x</version>
</dependency>

Previous versions

Branch Description
v0.1.x Based on GigaSpaces 10.1.1 and Java 8
gs14.5 Based on GigaSpaces 14.5 and Java 11

License

The GS-Test library is released under version 2.0 of the Apache License.

About

GS-Test is a set of utilities designed to simplify unit testing of applications implemented using GigaSpaces

Resources

Stars

Watchers

Forks

Packages

No packages published