Skip to content

Commit

Permalink
Use partitionGranularity for test seconds
Browse files Browse the repository at this point in the history
In ZipCachedFetchTest
  • Loading branch information
jacomago committed Oct 28, 2024
1 parent 5ebd454 commit 4f8a01b
Showing 1 changed file with 60 additions and 54 deletions.
114 changes: 60 additions & 54 deletions src/test/org/epics/archiverappliance/zipfs/ZipCachedFetchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.epics.archiverappliance.Event;
import org.epics.archiverappliance.EventStream;
import org.epics.archiverappliance.common.BasicContext;
import org.epics.archiverappliance.common.PartitionGranularity;
import org.epics.archiverappliance.common.TimeUtils;
import org.epics.archiverappliance.config.ArchDBRTypes;
import org.epics.archiverappliance.config.ConfigService;
Expand Down Expand Up @@ -50,35 +51,6 @@ public class ZipCachedFetchTest {
short currentYear = TimeUtils.getCurrentYear();
private ConfigService configService;

private static class ZipCachedFetchEventStream extends ArrayListEventStream implements Callable<EventStream> {
@Serial
private static final long serialVersionUID = 8076901507481457453L;

EventStream srcStream;

ZipCachedFetchEventStream(EventStream srcStream) {
super(0, (RemotableEventStreamDesc) srcStream.getDescription());
this.srcStream = srcStream;
}

@Override
public EventStream call() {
long previousEpochSeconds = 0L;
for (Event e : srcStream) {
long currEpochSeconds = e.getEpochSeconds();
if (currEpochSeconds - previousEpochSeconds > 60 * 60) {
this.add(e);
previousEpochSeconds = currEpochSeconds;
}
}
try {
srcStream.close();
} catch (Exception ignored) {
}
return this;
}
}

@BeforeEach
public void setUp() throws Exception {
configService = new ConfigServiceForTests(-1);
Expand All @@ -92,10 +64,13 @@ public void setUp() throws Exception {
ArchDBRTypes type = ArchDBRTypes.DBR_SCALAR_DOUBLE;
try (BasicContext context = new BasicContext()) {
for (int day = 0; day < 365; day++) {
ArrayListEventStream testData =
new ArrayListEventStream(24 * 60 * 60, new RemotableEventStreamDesc(type, pvName, currentYear));
int startofdayinseconds = day * 24 * 60 * 60;
for (int secondintoday = 0; secondintoday < 24 * 60 * 60; secondintoday++) {
ArrayListEventStream testData = new ArrayListEventStream(
PartitionGranularity.PARTITION_DAY.getApproxSecondsPerChunk(),
new RemotableEventStreamDesc(type, pvName, currentYear));
int startofdayinseconds = day * PartitionGranularity.PARTITION_DAY.getApproxSecondsPerChunk();
for (int secondintoday = 0;
secondintoday < PartitionGranularity.PARTITION_DAY.getApproxSecondsPerChunk();
secondintoday++) {
testData.add(new SimulationEvent(
startofdayinseconds + secondintoday, currentYear, type, new ScalarValue<Double>((double)
secondintoday)));
Expand All @@ -105,26 +80,6 @@ public void setUp() throws Exception {
}
}

@AfterEach
public void tearDown() throws Exception {
FileUtils.deleteDirectory(new File(rootFolderName));
}

@Test
public void test() throws Exception {
DecimalFormat format = new DecimalFormat("00");
for (int months = 2; months <= 9; months++) {
int startMonth = 2;
int endMonth = startMonth + months;
Instant startTime = TimeUtils.convertFromISO8601String(
currentYear + "-" + format.format(startMonth) + "-01T00:00:00.000Z");
Instant endTime = TimeUtils.convertFromISO8601String(
currentYear + "-" + format.format(endMonth) + "-30T00:00:00.000Z");
testParallelFetch(startTime, endTime, months);
testSerialFetch(startTime, endTime, months);
}
}

private void testSerialFetch(Instant startTime, Instant endTime, int months) throws Exception {
try (BasicContext context = new BasicContext()) {
long st0 = System.currentTimeMillis();
Expand All @@ -144,7 +99,8 @@ private void testSerialFetch(Instant startTime, Instant endTime, int months) thr
new MultiFilePBEventStream(paths, pvName, ArchDBRTypes.DBR_SCALAR_DOUBLE, startTime, endTime)) {
for (Event e : st) {
long currEpochSeconds = e.getEpochSeconds();
if (currEpochSeconds - previousEpochSeconds > 60 * 60) {
if (currEpochSeconds - previousEpochSeconds
> PartitionGranularity.PARTITION_HOUR.getApproxSecondsPerChunk()) {
eventCount++;
previousEpochSeconds = currEpochSeconds;
}
Expand All @@ -156,6 +112,26 @@ private void testSerialFetch(Instant startTime, Instant endTime, int months) thr
}
}

@AfterEach
public void tearDown() throws Exception {
FileUtils.deleteDirectory(new File(rootFolderName));
}

@Test
public void test() throws Exception {
DecimalFormat format = new DecimalFormat("00");
for (int months = 2; months <= 9; months++) {
int startMonth = 2;
int endMonth = startMonth + months;
Instant startTime = TimeUtils.convertFromISO8601String(
currentYear + "-" + format.format(startMonth) + "-01T00:00:00.000Z");
Instant endTime = TimeUtils.convertFromISO8601String(
currentYear + "-" + format.format(endMonth) + "-30T00:00:00.000Z");
testParallelFetch(startTime, endTime, months);
testSerialFetch(startTime, endTime, months);
}
}

private void testParallelFetch(Instant startTime, Instant endTime, int months) throws Exception {
ForkJoinPool forkJoinPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors() / 2);
logger.info("The parallelism in the pool is " + forkJoinPool.getParallelism());
Expand Down Expand Up @@ -211,4 +187,34 @@ private void testParallelFetch(Instant startTime, Instant endTime, int months) t
forkJoinPool.shutdown();
}
}

private static class ZipCachedFetchEventStream extends ArrayListEventStream implements Callable<EventStream> {
@Serial
private static final long serialVersionUID = 8076901507481457453L;

EventStream srcStream;

ZipCachedFetchEventStream(EventStream srcStream) {
super(0, (RemotableEventStreamDesc) srcStream.getDescription());
this.srcStream = srcStream;
}

@Override
public EventStream call() {
long previousEpochSeconds = 0L;
for (Event e : srcStream) {
long currEpochSeconds = e.getEpochSeconds();
if (currEpochSeconds - previousEpochSeconds
> PartitionGranularity.PARTITION_HOUR.getApproxSecondsPerChunk()) {
this.add(e);
previousEpochSeconds = currEpochSeconds;
}
}
try {
srcStream.close();
} catch (Exception ignored) {
}
return this;
}
}
}

0 comments on commit 4f8a01b

Please sign in to comment.