I was a little struggling the last hours to set up our integration test framework to create N embedded spaces and a cluster proxy for accessing those spaces.
Now it seems to work but there a few things I dont understand.
1. The creation of the embedded spaces is blocking for the 6 sec lookup timeout, I dont understand this. I do not want to search for an existing space but always create a new one. Is there a way to specify this in the configurer?
2. How should I setup the lookup service so that the cluster proxy can find the embedded spaces? Basically all spaces run in the same process so I was wondering if I even need to setup lookupgroups/locators and start an embedded LUS?
3. What "schema" shall I use?
4. What "cluster_schema" shall I use?
5. What other properties will make the space setup fast and stable?
In general I would like to have a lightweight space setup to make tests stable and fast.
This is what I do now (I also attached the code in a file): [C:\fakepath\MultiPartition.zip](/upfiles/14452710621071663.zip)
public class MultiPartitionTest {
private List closeAfter = new ArrayList<>();
private PlatformTransactionManager txManager;
@Before
public void beforeTest() throws Exception {
txManager = new DistributedJiniTxManagerConfigurer().transactionManager();
}
@After
public void afterTest() throws Exception {
closeAfter.forEach(Runnable::run);
}
private LinkedHashMap createPartitionedSpace(final int numberOfPartitions, final String spaceName) {
LinkedHashMap cluster = new LinkedHashMap<>(numberOfPartitions);
for (int partitionId = 1; partitionId <= numberOfPartitions; partitionId++) {
String url = spaceName
+ "?cluster_schema=partitioned"
+ "&create=true" // what does this do? it seems it has no effect
+ "&id=" + partitionId
+ "&total_members=" + numberOfPartitions;
EmbeddedSpaceConfigurer configurer = new EmbeddedSpaceConfigurer(url)
.versioned(true)
.schema("cache") // what is schema good for?
.lookupGroups("Test") // is this necessary?
.lookupTimeout(90) // uses 6 second timeout per default, but i dont need a timeout
.addProperty("fifo", "true")
.addProperty("space-config.engine.cache_policy", "0") // what is this good for?
.addProperty("space-config.lease_manager.expiration_time_interval", "500")
.addProperty("com.j_spaces.core.container.directory_services.jini_lus.start-embedded-lus", "true") // is this necessary?
.addProperty("com.j_spaces.core.container.directory_services.jini_lus.enabled", "true") // is this necessary?
.addProperty("com.j_spaces.core.container.directory_services.jndi.enabled", "false")
.addProperty("com.j_spaces.core.container.embedded-services.httpd.enabled", "false");
closeAfter.add(configurer::close);
GigaSpace space = new GigaSpaceConfigurer(configurer).transactionManager(txManager).clustered(false).gigaSpace();
cluster.put(partitionId, space);
}
return cluster;
}
private GigaSpace createClusterProxy(final String spaceName) {
String url = "jini://*/*/" + spaceName;
UrlSpaceConfigurer urlSpaceConfigurer = new UrlSpaceConfigurer(url).lookupGroups("Test").lookupTimeout(2500);
closeAfter.add(urlSpaceConfigurer::close);
return new GigaSpaceConfigurer(urlSpaceConfigurer).transactionManager(txManager).clustered(true).gigaSpace();
}
@Test
public void readingFromMultipleEmbeddedSpaces() {
// Given
LinkedHashMap spaceCluster = createPartitionedSpace(2, "SpaceA");
GigaSpace clusterProxy = createClusterProxy("SpaceA");
// When
for (int partitionId = 1; partitionId <= spaceCluster.entrySet().size(); partitionId++) {
SomePojo somePojo = new SomePojo(partitionId - 1);
spaceCluster.get(partitionId).write(somePojo);
}
// Then
for (int partitionId = 1; partitionId <= spaceCluster.entrySet().size(); partitionId++) {
SomePojo template = new SomePojo(partitionId - 1);
SomePojo actual = clusterProxy.read(template, 3000);
assertThat("Reading from partition " + partitionId, actual, notNullValue());
}
}
public static class SomePojo {
private String id;
private Integer routingKey;
public SomePojo() {
}
public SomePojo(final Integer routingKey) {
this.routingKey = routingKey;
}
@SpaceId(autoGenerate = true)
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
@SpaceRouting
public Integer getRoutingKey() {
return routingKey;
}
public void setRoutingKey(final Integer routingKey) {
this.routingKey = routingKey;
}
}
}
↧