Skip to content

Commit 7ad02c2

Browse files
committed
PIVOT-9331 Add test based on real files
1 parent bd33afc commit 7ad02c2

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* (C) ActiveViam 2020
3+
* ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY
4+
* property of ActiveViam. Any unauthorized use,
5+
* reproduction or transfer of this material is strictly prohibited
6+
*/
7+
8+
package com.activeviam.mac.statistic.memory.scenarios;
9+
10+
import com.activeviam.fwk.ActiveViamRuntimeException;
11+
import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig;
12+
import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig;
13+
import com.activeviam.mac.statistic.memory.ATestMemoryStatistic;
14+
import com.activeviam.pivot.utils.ApplicationInTests;
15+
import com.qfs.desc.IDatastoreSchemaDescription;
16+
import com.qfs.junit.LocalResourcesExtension;
17+
import com.qfs.monitoring.statistic.memory.IMemoryStatistic;
18+
import com.qfs.pivot.monitoring.impl.MemoryStatisticSerializerUtil;
19+
import com.qfs.store.IDatastore;
20+
import com.qfs.util.impl.QfsFileTestUtils;
21+
import com.quartetfs.biz.pivot.IActivePivotManager;
22+
import com.quartetfs.biz.pivot.definitions.IActivePivotManagerDescription;
23+
import com.quartetfs.biz.pivot.dto.CellSetDTO;
24+
import com.quartetfs.biz.pivot.query.impl.MDXQuery;
25+
import com.quartetfs.fwk.Registry;
26+
import com.quartetfs.fwk.contributions.impl.ClasspathContributionProvider;
27+
import com.quartetfs.fwk.query.QueryException;
28+
import java.io.IOException;
29+
import java.nio.file.Files;
30+
import java.nio.file.Path;
31+
import java.util.Collection;
32+
import java.util.List;
33+
import java.util.stream.Collectors;
34+
import org.junit.jupiter.api.Assertions;
35+
import org.junit.jupiter.api.BeforeAll;
36+
import org.junit.jupiter.api.Test;
37+
import org.junit.jupiter.api.extension.RegisterExtension;
38+
39+
/** The scenario this test produces has a cube level {@code id} with a nullable dictionary. */
40+
public class TestMissingChunkId {
41+
42+
protected static final Path TEMP_DIRECTORY =
43+
QfsFileTestUtils.createTempDirectory(TestMultipleFieldsDictionary.class);
44+
@RegisterExtension protected LocalResourcesExtension resources = new LocalResourcesExtension();
45+
protected IDatastore monitoredDatastore;
46+
protected IActivePivotManager monitoredManager;
47+
protected Path statisticsPath;
48+
protected IDatastore monitoringDatastore;
49+
50+
@BeforeAll
51+
public static void setupRegistry() {
52+
Registry.setContributionProvider(new ClasspathContributionProvider());
53+
}
54+
55+
protected ApplicationInTests createAnalysisApplication() {
56+
final IDatastoreSchemaDescription desc =
57+
new MemoryAnalysisDatastoreDescriptionConfig().datastoreSchemaDescription();
58+
final IActivePivotManagerDescription manager =
59+
new ManagerDescriptionConfig().managerDescription();
60+
return ApplicationInTests.builder().withDatastore(desc).withManager(manager).build();
61+
}
62+
63+
protected Collection<IMemoryStatistic> loadMemoryStatistic(final Path path) throws IOException {
64+
return Files.list(path)
65+
.map(
66+
file -> {
67+
try {
68+
return MemoryStatisticSerializerUtil.readStatisticFile(file.toFile());
69+
} catch (IOException exception) {
70+
throw new ActiveViamRuntimeException(exception);
71+
}
72+
})
73+
.collect(Collectors.toList());
74+
}
75+
76+
protected void loadStatisticsIntoDatastore(
77+
final Collection<? extends IMemoryStatistic> statistics, final IDatastore analysisDatastore) {
78+
ATestMemoryStatistic.feedMonitoringApplication(analysisDatastore, statistics, "test");
79+
}
80+
81+
@Test
82+
public void testStatisticLoading() throws IOException {
83+
final Path statisticsPath =
84+
Path.of("src", "test", "resources", "stats_files_with_missing_chunk_id");
85+
final Collection<IMemoryStatistic> memoryStatistics = loadMemoryStatistic(statisticsPath);
86+
87+
final IDatastore analysisDatastore = (IDatastore) createAnalysisApplication().getDatabase();
88+
89+
Assertions.assertDoesNotThrow(
90+
() -> loadStatisticsIntoDatastore(memoryStatistics, analysisDatastore));
91+
}
92+
93+
@Test
94+
public void testGeneratio0nOfMissingChunkId() throws IOException, QueryException {
95+
final Path statisticsPath =
96+
Path.of("src", "test", "resources", "stats_files_with_missing_chunk_id");
97+
final Collection<IMemoryStatistic> memoryStatistics = loadMemoryStatistic(statisticsPath);
98+
99+
final ApplicationInTests analysisApplication = createAnalysisApplication();
100+
resources.register(analysisApplication).start();
101+
loadStatisticsIntoDatastore(memoryStatistics, (IDatastore) analysisApplication.getDatabase());
102+
103+
final MDXQuery query =
104+
new MDXQuery(
105+
"SELECT"
106+
+ " NON EMPTY Hierarchize("
107+
+ " Descendants("
108+
+ " {"
109+
+ " [Chunks].[ChunkId].[ALL].[AllMember]"
110+
+ " },"
111+
+ " 1,"
112+
+ " SELF_AND_BEFORE"
113+
+ " )"
114+
+ " ) ON ROWS"
115+
+ " FROM [MemoryCube]");
116+
117+
final CellSetDTO totalResult = analysisApplication.getSingleCube().execute(query);
118+
final List<String> chunkIds =
119+
totalResult.getAxes().get(0).getPositions().stream()
120+
.map(p -> p.getMembers().get(0).getCaption())
121+
.collect(Collectors.toList());
122+
final List<String> expectedChunkIds = List.of("-1", "-2", "-3");
123+
124+
org.assertj.core.api.Assertions.assertThat(chunkIds).containsAll(expectedChunkIds);
125+
}
126+
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)