Skip to content

Commit 253ed46

Browse files
committed
[CALCITE-7261] DiffRepository generation xml does not respect alphabetical order
1 parent c18c045 commit 253ed46

File tree

3 files changed

+100
-4
lines changed

3 files changed

+100
-4
lines changed

testkit/src/main/java/org/apache/calcite/test/DiffRepository.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ private synchronized void update(
586586
int i = 0;
587587
final List<String> names = Pair.left(map);
588588
for (String s : names) {
589-
if (s.compareToIgnoreCase(testCaseName) <= 0) {
589+
if (s.compareTo(testCaseName) <= 0) {
590590
++i;
591591
}
592592
}
@@ -598,13 +598,13 @@ private synchronized void update(
598598
// will end up in exactly the right position, and if the list is not sorted,
599599
// the new item will end up in approximately the right position.
600600
while (i < map.size()
601-
&& names.get(i).compareToIgnoreCase(testCaseName) < 0) {
601+
&& names.get(i).compareTo(testCaseName) < 0) {
602602
++i;
603603
}
604-
if (i >= map.size() - 1) {
604+
if (i > map.size() - 1) {
605605
return null;
606606
}
607-
while (i >= 0 && names.get(i).compareToIgnoreCase(testCaseName) > 0) {
607+
while (i >= 0 && names.get(i).compareTo(testCaseName) > 0) {
608608
--i;
609609
}
610610
return map.get(i + 1).right;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
package org.apache.calcite.test;
18+
19+
import org.junit.jupiter.api.AfterAll;
20+
import org.junit.jupiter.api.Test;
21+
22+
import java.io.IOException;
23+
import java.nio.file.Files;
24+
import java.nio.file.Paths;
25+
26+
import static org.hamcrest.MatcherAssert.assertThat;
27+
import static org.hamcrest.Matchers.endsWith;
28+
29+
/**
30+
* Tests checking generated actual XML version.
31+
*
32+
* <p>Test case for
33+
* <a href="https://issues.apache.org/jira/browse/CALCITE-7261">[CALCITE-7261]
34+
* DiffRepository generation xml doesn't respect alphabetical order</a>.
35+
*/
36+
public class DiffRepositoryGeneratedFileTest {
37+
private static final DiffRepository REPO =
38+
DiffRepository.lookup(DiffRepositoryGeneratedFileTest.class);
39+
40+
@AfterAll
41+
static void tearDown() throws IOException {
42+
final String fileContent =
43+
String.join("\n", Files.readAllLines(Paths.get(REPO.logFilePath())));
44+
assertThat(
45+
fileContent, endsWith(
46+
"<Root>\n"
47+
+ " <TestCase name=\"testDiff\">\n"
48+
+ " <Resource name=\"resource\">\n"
49+
+ " <![CDATA[diff]]>\n"
50+
+ " </Resource>\n"
51+
+ " </TestCase>\n"
52+
+ " <TestCase name=\"testNull\">\n"
53+
+ " <Resource name=\"resource\">\n"
54+
+ " <![CDATA[null]]>\n"
55+
+ " </Resource>\n"
56+
+ " </TestCase>\n"
57+
+ " <TestCase name=\"testmulti\">\n"
58+
+ " <Resource name=\"resource\">\n"
59+
+ " <![CDATA[multi]]>\n"
60+
+ " </Resource>\n"
61+
+ " </TestCase>\n"
62+
+ "</Root>"));
63+
}
64+
65+
@Test void testDiff() {
66+
REPO.set("resource", "diff");
67+
}
68+
69+
// Here method name was intentionally written in lower case to highlight
70+
// discrepancy between checking logic and generated logic
71+
@Test void testmulti() {
72+
REPO.set("resource", "multi");
73+
}
74+
75+
@Test void testNull() {
76+
REPO.set("resource", "null");
77+
}
78+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to you under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
<Root></Root>

0 commit comments

Comments
 (0)