Skip to content

Commit

Permalink
Fixed hz-cluster unit test error on Windows and clean up test files.
Browse files Browse the repository at this point in the history
  • Loading branch information
sikeoka committed Dec 13, 2018
1 parent 2469eca commit b8823d5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,63 @@
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.geoserver.cluster.hazelcast.HzSynchronizer;
import org.geoserver.cluster.hazelcast.HzSynchronizerTest;
import org.geoserver.platform.GeoServerResourceLoader;
import org.geoserver.platform.resource.Resource;
import org.geoserver.platform.resource.Resources;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/** @author Alessio Fabiani, GeoSolutions */
public class ConfigTest extends HzSynchronizerTest {

private Resource tmpDir;
private Resource tmpDir1;
private Resource tmpDir2;

@Before
public void createTempDirs() throws IOException {
tmpDir = tmpDir();
tmpDir1 = tmpDir();
tmpDir2 = tmpDir();
}

@After
public void deleteTempDirs() {
FileUtils.deleteQuietly(tmpDir.dir());
FileUtils.deleteQuietly(tmpDir1.dir());
FileUtils.deleteQuietly(tmpDir2.dir());
}

@Test
public void testConfigurationReload() throws IOException {
Resource tmpDir1 = tmpDir();
Resource tmpDir2 = tmpDir();
GeoServerResourceLoader resourceLoader = new GeoServerResourceLoader(tmpDir.dir());
GeoServerResourceLoader resourceLoader1 = new GeoServerResourceLoader(tmpDir1.dir());
GeoServerResourceLoader resourceLoader2 = new GeoServerResourceLoader(tmpDir2.dir());
Resources.directory(tmpDir.get("cluster"), true);
Resources.directory(tmpDir1.get("cluster"), true);
Resources.directory(tmpDir2.get("cluster"), true);

this.cluster.setResourceStore(resourceLoader1.getResourceStore());
this.cluster.setResourceStore(resourceLoader.getResourceStore());
this.cluster.saveConfiguration(resourceLoader1);

assertNotNull(cluster.getFileLocations());
assertEquals(2, cluster.getFileLocations().size());

assertTrue(
"The file 'cluster.properties' does not exist!",
Resources.exists(tmpDir1.get("cluster/cluster.properties")));
assertTrue(
"The file 'hazelcast.xml' does not exist!",
Resources.exists(tmpDir1.get("cluster/hazelcast.xml")));

this.cluster.saveConfiguration(resourceLoader2);

assertTrue(
Expand All @@ -45,17 +76,21 @@ public void testConfigurationReload() throws IOException {
Resources.exists(tmpDir2.get("cluster/hazelcast.xml")));

assertEquals(
IOUtils.readLines(tmpDir1.get("cluster/cluster.properties").in()),
IOUtils.readLines(tmpDir2.get("cluster/cluster.properties").in()));
lines(tmpDir1, "cluster/cluster.properties"),
lines(tmpDir2, "cluster/cluster.properties"));

assertEquals(
IOUtils.readLines(tmpDir1.get("cluster/hazelcast.xml").in()),
IOUtils.readLines(tmpDir2.get("cluster/hazelcast.xml").in()));
lines(tmpDir1, "cluster/hazelcast.xml"), lines(tmpDir2, "cluster/hazelcast.xml"));
}

@Override
protected HzSynchronizer getSynchronizer() {
// TODO Auto-generated method stub
return null;
}

private static final List<String> lines(Resource dir, String path) throws IOException {
try (InputStream input = dir.get(path).in()) {
return IOUtils.readLines(input, StandardCharsets.UTF_8);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,12 @@ protected void waitForSync() throws Exception {
super.waitForSync();
// Wait up to 5 seconds for the executor to be ready for the next reload.
ThreadPoolExecutor executor = ((ReloadHzSynchronizer) sync).reloadService;
for (int i = 0; i < 200; i++) {
if (executor.getActiveCount() == 0) {
return;
}
for (int i = 0; i < 200 && executor.getActiveCount() > 0; i++) {
try {
Thread.sleep(25);
} catch (InterruptedException e) {
}
}
executor.purge();
}
}

0 comments on commit b8823d5

Please sign in to comment.