Skip to content

Commit 8509774

Browse files
committed
IGNITE-24777 Add test
1 parent 39e481c commit 8509774

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/FilePerformanceStatisticsWriter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ private static File resolveStatisticsFile(GridKernalContext ctx) throws IgniteCh
511511
}
512512

513513
/** Writes {@link UUID} to buffer. */
514-
private static void writeUuid(ByteBuffer buf, UUID uuid) {
514+
static void writeUuid(ByteBuffer buf, UUID uuid) {
515515
buf.putLong(uuid.getMostSignificantBits());
516516
buf.putLong(uuid.getLeastSignificantBits());
517517
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.processors.performancestatistics;
19+
20+
import java.io.File;
21+
import java.nio.ByteBuffer;
22+
import java.nio.ByteOrder;
23+
import java.util.HashMap;
24+
import java.util.Map;
25+
import java.util.UUID;
26+
import org.apache.ignite.internal.processors.cache.persistence.file.FileIO;
27+
import org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory;
28+
import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
29+
import org.apache.ignite.internal.util.typedef.internal.U;
30+
import org.junit.Test;
31+
32+
import static java.util.Collections.singletonList;
33+
import static java.util.UUID.randomUUID;
34+
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.PERF_STAT_DIR;
35+
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.writeString;
36+
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.writeUuid;
37+
38+
/**
39+
* Tests forward read mode for {@link OperationType#QUERY_PROPERTY} records.
40+
*/
41+
public class ForwardReadQueryPropertyTest extends AbstractPerformanceStatisticsTest {
42+
/** Read buffer size. */
43+
private static final int BUFFER_SIZE = 100;
44+
45+
/** @throws Exception If failed. */
46+
@Test
47+
public void testStringForwardRead() throws Exception {
48+
File dir = U.resolveWorkDirectory(U.defaultWorkDirectory(), PERF_STAT_DIR, false);
49+
50+
Map<String, String> expProps = createStatistics(dir);
51+
Map<String, String> actualProps = new HashMap<>();
52+
53+
new FilePerformanceStatisticsReader(BUFFER_SIZE, new TestHandler() {
54+
@Override public void queryProperty(UUID nodeId, GridCacheQueryType type, UUID qryNodeId, long id, String name,
55+
String val) {
56+
assertNotNull(name);
57+
assertNotNull(val);
58+
59+
actualProps.put(name, val);
60+
}
61+
}).read(singletonList(dir));
62+
63+
assertEquals(expProps, actualProps);
64+
}
65+
66+
/** Creates test performance statistics file. */
67+
private Map<String, String> createStatistics(File dir) throws Exception {
68+
File file = new File(dir, "node-" + randomUUID() + ".prf");
69+
70+
try (FileIO fileIo = new RandomAccessFileIOFactory().create(file)) {
71+
ByteBuffer buf = ByteBuffer.allocate(1024).order(ByteOrder.nativeOrder());
72+
73+
buf.put(OperationType.VERSION.id());
74+
buf.putShort(FilePerformanceStatisticsWriter.FILE_FORMAT_VERSION);
75+
76+
writeQueryProperty(buf, "property", true, "val", true);
77+
writeQueryProperty(buf, "property", false, "val", false);
78+
writeQueryProperty(buf, "propertyNan", true, "valNan", true);
79+
80+
buf.flip();
81+
82+
fileIo.write(buf);
83+
84+
fileIo.force();
85+
}
86+
87+
return Map.of("property", "val");
88+
}
89+
90+
/** */
91+
private static void writeQueryProperty(ByteBuffer buf, String name, boolean nameCached, String val, boolean valCached) {
92+
buf.put(OperationType.QUERY_PROPERTY.id());
93+
94+
writeString(buf, name, nameCached);
95+
writeString(buf, val, valCached);
96+
97+
buf.put((byte)GridCacheQueryType.SQL_FIELDS.ordinal());
98+
99+
writeUuid(buf, randomUUID());
100+
101+
buf.putLong(0);
102+
}
103+
}

modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicWithPersistenceTestSuite.java

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.apache.ignite.internal.processors.cache.persistence.SingleNodePersistenceSslTest;
4343
import org.apache.ignite.internal.processors.performancestatistics.CacheStartTest;
4444
import org.apache.ignite.internal.processors.performancestatistics.CheckpointTest;
45+
import org.apache.ignite.internal.processors.performancestatistics.ForwardReadQueryPropertyTest;
4546
import org.apache.ignite.internal.processors.performancestatistics.ForwardReadTest;
4647
import org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsMultipleStartTest;
4748
import org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsPropertiesTest;
@@ -103,6 +104,7 @@
103104
PerformanceStatisticsPropertiesTest.class,
104105
PerformanceStatisticsMultipleStartTest.class,
105106
ForwardReadTest.class,
107+
ForwardReadQueryPropertyTest.class,
106108
CacheStartTest.class,
107109
CheckpointTest.class
108110
})

0 commit comments

Comments
 (0)