-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DataGroupReadTest in preparation for DM-14029.
- introduce test category - add howto section for Test in Developer Setup.txt doc.
- Loading branch information
Showing
6 changed files
with
173 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
org.gradle.jvmargs=-Xms256m -Xmx2048m | ||
org.gradle.jvmargs=-Xms256m -Xmx8048m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package edu.caltech.ipac; | ||
|
||
/** | ||
* category markers. use for include/exclude tests | ||
*/ | ||
public class TestCategory { | ||
public interface Perf{} | ||
public interface Integration{} | ||
} |
129 changes: 129 additions & 0 deletions
129
src/firefly/test/edu/caltech/ipac/firefly/server/util/tables/DataGroupReadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt | ||
*/ | ||
package edu.caltech.ipac.firefly.server.util.tables; | ||
|
||
import edu.caltech.ipac.astro.FITSTableReader; | ||
import edu.caltech.ipac.util.VoTableUtil; | ||
import edu.caltech.ipac.TestCategory; | ||
import edu.caltech.ipac.firefly.server.util.ipactable.DataGroupReader; | ||
import edu.caltech.ipac.firefly.util.FileLoader; | ||
import edu.caltech.ipac.util.DataGroup; | ||
import edu.caltech.ipac.util.DataType; | ||
import edu.caltech.ipac.util.IpacTableUtil; | ||
|
||
import nom.tam.fits.FitsException; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.lang.management.ManagementFactory; | ||
import java.lang.management.MemoryPoolMXBean; | ||
import java.lang.management.MemoryUsage; | ||
import java.util.List; | ||
|
||
/** | ||
* @author loi | ||
* @version $Id: IpacTableParser.java,v 1.18 2011/12/08 19:34:02 loi Exp $ | ||
*/ | ||
public class DataGroupReadTest { | ||
|
||
private static final File largeIpacTable = FileLoader.resolveFile(DataGroupReadTest.class, "50k.tbl"); | ||
private static final File ipacTable = FileLoader.resolveFile(DataGroupReadTest.class, "DataGroupTest.tbl"); | ||
private static final File voTable = FileLoader.resolveFile(DataGroupReadTest.class, "p3am_cdd.xml"); | ||
private static final File fitsTable = FileLoader.resolveFile(DataGroupReadTest.class, "lsst-table.fits"); | ||
|
||
@Test | ||
public void ipacTable() throws IOException { | ||
DataGroup data = DataGroupReader.read(ipacTable); | ||
Assert.assertNotNull(data); | ||
|
||
// test col header | ||
DataType ra = data.getDataDefintion("ra"); | ||
Assert.assertEquals("column name", "ra", ra.getKeyName()); | ||
Assert.assertEquals("column unit", "deg", ra.getDataUnit()); | ||
Assert.assertEquals("column desc", "null", ra.getNullString()); | ||
Assert.assertEquals("column type", "double", ra.getTypeDesc()); | ||
|
||
// test col attributes | ||
String width = data.getAttribute(IpacTableUtil.makeAttribKey(IpacTableUtil.WIDTH_TAG, "designation")).getValue(); | ||
String prefWidth = data.getAttribute(IpacTableUtil.makeAttribKey(IpacTableUtil.PREF_WIDTH_TAG, "designation")).getValue(); | ||
String sortable = data.getAttribute(IpacTableUtil.makeAttribKey(IpacTableUtil.SORTABLE_TAG, "designation")).getValue(); | ||
String filterable = data.getAttribute(IpacTableUtil.makeAttribKey(IpacTableUtil.FILTERABLE_TAG, "designation")).getValue(); | ||
String visibility = data.getAttribute(IpacTableUtil.makeAttribKey(IpacTableUtil.VISI_TAG, "designation")).getValue(); | ||
Assert.assertEquals("column width", "100", width); | ||
Assert.assertEquals("column prefWidth", "10", prefWidth); | ||
Assert.assertEquals("column sortable", "false", sortable); | ||
Assert.assertEquals("column filterable", "true", filterable); | ||
Assert.assertEquals("column visibility", "hidden", visibility); | ||
|
||
// random value test | ||
Assert.assertEquals("cell (ra, 4)", 10.744471, data.get(4).getDataElement("ra")); // in the middle | ||
Assert.assertEquals("cell (h_msigcom, 0)", null, data.get(0).getDataElement("h_msigcom")); // first row with null value | ||
Assert.assertEquals("cell (err_min, 15)", 0.29, data.get(15).getDataElement("err_min")); // last row | ||
} | ||
|
||
@Test | ||
public void voTable() throws IOException { | ||
DataGroup data = VoTableUtil.voToDataGroups(voTable.getPath())[0]; | ||
Assert.assertNotNull(data); | ||
Assert.assertEquals("Number of rows", 40, data.size()); | ||
Assert.assertEquals("Number of columns", 20, data.getDataDefinitions().length); | ||
|
||
// random value test | ||
Assert.assertEquals("cell (magzip2, 0)", 0.006, data.get(0).getDataElement("magzip2")); // first row | ||
Assert.assertEquals("cell (magzip, 9)", 19.5, data.get(9).getDataElement("magzip")); // in the middle | ||
Assert.assertEquals("cell (magzip, 39)", 13.0, data.get(39).getDataElement("magzip")); // last row | ||
} | ||
|
||
@Test | ||
public void fitsTable() throws IOException, FitsException { | ||
DataGroup data = FITSTableReader.convertFitsToDataGroup(fitsTable.getPath(), null, null, null, 0); | ||
Assert.assertNotNull(data); | ||
Assert.assertEquals("Number of rows", 765, data.size()); | ||
Assert.assertEquals("Number of columns", 52, data.getDataDefinitions().length); | ||
|
||
// random value test | ||
Assert.assertEquals("cell (coord_ra, 0)", 6.13602424, getDouble(data.get(0).getDataElement("coord_ra")), 0.00000001); // first row | ||
Assert.assertEquals("cell (footprint, 24)", 25, data.get(24).getDataElement("footprint")); // in the middle | ||
Assert.assertEquals("cell (base_GaussianCentroid_x, 764)", 850.043863, getDouble(data.get(764).getDataElement("base_GaussianCentroid_x")), 0.000001); // last row | ||
} | ||
|
||
@Category({TestCategory.Perf.class}) | ||
@Test | ||
public void perfTest() throws IOException { | ||
|
||
Runtime.getRuntime().gc(); | ||
long beginMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); | ||
long start = System.currentTimeMillis(); | ||
|
||
DataGroup data = DataGroupReader.read(largeIpacTable); | ||
|
||
long elapsed = System.currentTimeMillis() - start; | ||
long usedB4Gc = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() - beginMem; | ||
Runtime.getRuntime().gc(); | ||
long usedAfGc = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() - beginMem; | ||
|
||
System.out.printf("Memory temp=%.2fMB final:%.2fMB elapsed:%.2fsecs %n", usedB4Gc/1000/1000.0, usedAfGc/1000/1000.0, elapsed/1000.0); | ||
Assert.assertNotNull(data); | ||
Assert.assertEquals("Number of rows", 49933, data.size()); | ||
|
||
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); | ||
for (MemoryPoolMXBean pool : pools) { | ||
MemoryUsage peak = pool.getPeakUsage(); | ||
System.out.printf("Peak %s memory used: %,d %n", pool.getName(), peak.getUsed()); | ||
} | ||
} | ||
|
||
|
||
private static double getDouble(Object val) { | ||
if (val instanceof Double) { | ||
return (Double) val; | ||
} else { | ||
return Double.parseDouble(String.valueOf(val)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters