Skip to content

Commit 0501cdc

Browse files
committed
iter
1 parent 3b2c9e1 commit 0501cdc

File tree

7 files changed

+327
-18
lines changed

7 files changed

+327
-18
lines changed

gradle/verification-metadata.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4066,6 +4066,11 @@
40664066
<sha256 value="8f1049ee24b34a10b60cd810048099f781c2658cde2181e831496ab30a982985" origin="Generated by Gradle"/>
40674067
</artifact>
40684068
</component>
4069+
<component group="org.junit.jupiter" name="junit-jupiter-api" version="5.11.3">
4070+
<artifact name="junit-jupiter-api-5.11.3.jar">
4071+
<sha256 value="5d8147a60f49453973e250ed68701b7ff055964fe2462fc2cb1ec1d6d44889ba" origin="Generated by Gradle"/>
4072+
</artifact>
4073+
</component>
40694074
<component group="org.junit.jupiter" name="junit-jupiter-api" version="5.12.0">
40704075
<artifact name="junit-jupiter-api-5.12.0.jar">
40714076
<sha256 value="1f601eee82e3ac8889e53b042d3ff4eba0d60f367da269d78830f598d5df345e" origin="Generated by Gradle"/>
@@ -4076,6 +4081,11 @@
40764081
<sha256 value="ce3374a7efba605e2d2b69a3fef90134032bab3ecc3ed8579a4871b1c2c4729c" origin="Generated by Gradle"/>
40774082
</artifact>
40784083
</component>
4084+
<component group="org.junit.jupiter" name="junit-jupiter-engine" version="5.11.3">
4085+
<artifact name="junit-jupiter-engine-5.11.3.jar">
4086+
<sha256 value="e62420c99f7c0d59a2159a2ef63e61877e9c80bd722c03ca8bf3bdcea050a589" origin="Generated by Gradle"/>
4087+
</artifact>
4088+
</component>
40794089
<component group="org.junit.jupiter" name="junit-jupiter-engine" version="5.12.0">
40804090
<artifact name="junit-jupiter-engine-5.12.0.jar">
40814091
<sha256 value="a06284870cb9afe7dd15ac06f48ac45dbf0039716f335c62d5cad6ee2600cee9" origin="Generated by Gradle"/>
@@ -4086,6 +4096,11 @@
40864096
<sha256 value="4689bc902255a19fe98277683ba3231c094d107c54c8d35f2b6f9c97d226418e" origin="Generated by Gradle"/>
40874097
</artifact>
40884098
</component>
4099+
<component group="org.junit.jupiter" name="junit-jupiter-params" version="5.11.3">
4100+
<artifact name="junit-jupiter-params-5.11.3.jar">
4101+
<sha256 value="0f798ebec744c4e6605fd4f2072f41a8e989e2d469e21db5aa67cf799c0b51ec" origin="Generated by Gradle"/>
4102+
</artifact>
4103+
</component>
40894104
<component group="org.junit.jupiter" name="junit-jupiter-params" version="5.12.0">
40904105
<artifact name="junit-jupiter-params-5.12.0.jar">
40914106
<sha256 value="a4788fe6e25e7f54a478955cc70a96b21c9aa2bbd9f5b601f14050351d1da37d" origin="Generated by Gradle"/>
@@ -4096,6 +4111,11 @@
40964111
<sha256 value="389b8d13a8d8872fcbd4f0eba7b2c46afc628419f9a1b2a3a9f93241a06a7218" origin="Generated by Gradle"/>
40974112
</artifact>
40984113
</component>
4114+
<component group="org.junit.platform" name="junit-platform-commons" version="1.11.3">
4115+
<artifact name="junit-platform-commons-1.11.3.jar">
4116+
<sha256 value="be262964b0b6b48de977c61d4f931df8cf61e80e750cc3f3a0a39cdd21c1008c" origin="Generated by Gradle"/>
4117+
</artifact>
4118+
</component>
40994119
<component group="org.junit.platform" name="junit-platform-commons" version="1.12.0">
41004120
<artifact name="junit-platform-commons-1.12.0.jar">
41014121
<sha256 value="8914fca20882c8476a9165053a947973559e539298c285f4de5bdec36663b34a" origin="Generated by Gradle"/>
@@ -4106,6 +4126,11 @@
41064126
<sha256 value="fa4fa68c8bd54dd0cb49c3fcbe9b2e42f4da6bedbe7e7ccf2a05f1a1e609b593" origin="Generated by Gradle"/>
41074127
</artifact>
41084128
</component>
4129+
<component group="org.junit.platform" name="junit-platform-engine" version="1.11.3">
4130+
<artifact name="junit-platform-engine-1.11.3.jar">
4131+
<sha256 value="0043f72f611664735da8dc9a308bf12ecd2236b05339351c4741edb4d8fab0da" origin="Generated by Gradle"/>
4132+
</artifact>
4133+
</component>
41094134
<component group="org.junit.platform" name="junit-platform-engine" version="1.12.0">
41104135
<artifact name="junit-platform-engine-1.12.0.jar">
41114136
<sha256 value="bd38897bcbe183659234c6d75955ad1b937302f894f25e42cdc9aee0dd8ae614" origin="Generated by Gradle"/>
@@ -4116,6 +4141,11 @@
41164141
<sha256 value="702868ed7e86b9b4672ede0f1e185e905baca9afab57746a7c650be3c7bca047" origin="Generated by Gradle"/>
41174142
</artifact>
41184143
</component>
4144+
<component group="org.junit.platform" name="junit-platform-launcher" version="1.11.3">
4145+
<artifact name="junit-platform-launcher-1.11.3.jar">
4146+
<sha256 value="b4727459201b0011beb0742bd807421a1fc8426b116193031ed87825bc2d4f04" origin="Generated by Gradle"/>
4147+
</artifact>
4148+
</component>
41194149
<component group="org.junit.platform" name="junit-platform-launcher" version="1.12.0">
41204150
<artifact name="junit-platform-launcher-1.12.0.jar">
41214151
<sha256 value="fe6550658aaa21ca1f28b7279a5e60c68c8fa68f7de22a891ef64ac44cf36f15" origin="Generated by Gradle"/>
@@ -4126,21 +4156,41 @@
41264156
<sha256 value="83a9ed68adcb76e60316a4d682fc48507865df2f0ab35f82695cc9995410e05e" origin="Generated by Gradle"/>
41274157
</artifact>
41284158
</component>
4159+
<component group="org.junit.platform" name="junit-platform-reporting" version="1.11.3">
4160+
<artifact name="junit-platform-reporting-1.11.3.jar">
4161+
<sha256 value="b8e19dbebcae7d1ff30b9d767047fbf3694027c33dfa423b371693b7f6679ed1" origin="Generated by Gradle"/>
4162+
</artifact>
4163+
</component>
41294164
<component group="org.junit.platform" name="junit-platform-reporting" version="1.12.0">
41304165
<artifact name="junit-platform-reporting-1.12.0.jar">
41314166
<sha256 value="cb5c2dd87cb1f46f8cc5954e48e76e5719776cf942d6e4df1588c6ef4fdefcec" origin="Generated by Gradle"/>
41324167
</artifact>
41334168
</component>
4169+
<component group="org.junit.platform" name="junit-platform-suite-api" version="1.11.3">
4170+
<artifact name="junit-platform-suite-api-1.11.3.jar">
4171+
<sha256 value="c728aa61ccd7942552f8bd4e50ec3064260d4a1e085022cbfccd64a88f9b3820" origin="Generated by Gradle"/>
4172+
</artifact>
4173+
</component>
41344174
<component group="org.junit.platform" name="junit-platform-suite-api" version="1.12.0">
41354175
<artifact name="junit-platform-suite-api-1.12.0.jar">
41364176
<sha256 value="d460ff55f3740addbd780a760d3c7e9af5512b44daaf4b150a2fdc53bdc49be7" origin="Generated by Gradle"/>
41374177
</artifact>
41384178
</component>
4179+
<component group="org.junit.platform" name="junit-platform-suite-commons" version="1.11.3">
4180+
<artifact name="junit-platform-suite-commons-1.11.3.jar">
4181+
<sha256 value="1369846b83b7ea6f24670b2b4d8a372a1bbbc844e2746f5a93396b5a13a28ca6" origin="Generated by Gradle"/>
4182+
</artifact>
4183+
</component>
41394184
<component group="org.junit.platform" name="junit-platform-suite-commons" version="1.12.0">
41404185
<artifact name="junit-platform-suite-commons-1.12.0.jar">
41414186
<sha256 value="aa7e0c70b54aef673dfb1202117091b43d10c0d0121ff848185df0a79fe16cb5" origin="Generated by Gradle"/>
41424187
</artifact>
41434188
</component>
4189+
<component group="org.junit.platform" name="junit-platform-suite-engine" version="1.11.3">
4190+
<artifact name="junit-platform-suite-engine-1.11.3.jar">
4191+
<sha256 value="b09dda0a52850bfb7cb8b94b76225b0245cac9dd3fa2d3cc4beef68dc255e6ca" origin="Generated by Gradle"/>
4192+
</artifact>
4193+
</component>
41444194
<component group="org.junit.platform" name="junit-platform-suite-engine" version="1.12.0">
41454195
<artifact name="junit-platform-suite-engine-1.12.0.jar">
41464196
<sha256 value="db03c569e7cfb1dab94d990d9d7aecf61b906a594d33b860292f5f51e0de4b71" origin="Generated by Gradle"/>

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,8 +2558,8 @@ private static XContentType randomSupportedContentType() {
25582558
}
25592559

25602560
public static void addXContentBody(Request request, ToXContent body) throws IOException {
2561-
final var xContentType = randomSupportedContentType();
2562-
final var bodyBytes = XContentHelper.toXContent(body, xContentType, EMPTY_PARAMS, randomBoolean());
2561+
final var xContentType = XContentType.JSON;
2562+
final var bodyBytes = XContentHelper.toXContent(body, xContentType, EMPTY_PARAMS, false);
25632563
request.setEntity(
25642564
new InputStreamEntity(
25652565
bodyBytes.streamInput(),
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
apply plugin: 'elasticsearch.internal-java-rest-test'
22

33
dependencies {
4-
javaRestTestImplementation("org.junit.jupiter:junit-jupiter-api:5.12.0")
5-
javaRestTestImplementation("org.junit.jupiter:junit-jupiter-params:5.12.0")
6-
javaRestTestRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.12.0")
7-
javaRestTestRuntimeOnly("org.junit.platform:junit-platform-launcher:1.12.0")
8-
javaRestTestRuntimeOnly("org.junit.platform:junit-platform-commons:1.12.0")
9-
javaRestTestRuntimeOnly("org.junit.platform:junit-platform-reporting:1.12.0")
4+
// https://junit.org/junit5/docs/current/user-guide/#dependency-metadata
5+
javaRestTestImplementation("org.junit.jupiter:junit-jupiter-api:5.11.3")
6+
javaRestTestImplementation("org.junit.jupiter:junit-jupiter-params:5.11.3")
7+
javaRestTestImplementation("org.junit.jupiter:junit-jupiter-engine:5.11.3")
8+
javaRestTestRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.3")
9+
javaRestTestRuntimeOnly("org.junit.platform:junit-platform-engine:1.11.3")
10+
javaRestTestRuntimeOnly("org.junit.platform:junit-platform-commons:1.11.3")
11+
javaRestTestRuntimeOnly("org.junit.platform:junit-platform-reporting:1.11.3")
12+
javaRestTestRuntimeOnly("org.junit.platform:junit-platform-suite-api:1.11.3")
13+
javaRestTestRuntimeOnly("org.junit.platform:junit-platform-suite-commons:1.11.3")
14+
javaRestTestRuntimeOnly("org.junit.platform:junit-platform-suite-engine:1.11.3")
15+
javaRestTestRuntimeOnly("org.opentest4j:opentest4j:1.3.0")
1016

1117
javaRestTestImplementation("net.jqwik:jqwik-api:1.9.2")
12-
javaRestTestCompileOnly("org.apiguardian:apiguardian-api:1.0.0")
13-
javaRestTestRuntimeOnly("net.jqwik:jqwik-engine:1.9.2")
18+
javaRestTestCompileOnly("org.apiguardian:apiguardian-api:1.1.2")
19+
javaRestTestImplementation("net.jqwik:jqwik-engine:1.9.2")
1420
}
1521

1622
tasks.named("javaRestTest").configure {
23+
usesDefaultDistribution()
24+
1725
useJUnitPlatform {
18-
includeEngines 'jqwik'
26+
includeEngines("junit-jupiter")
27+
includeEngines('jqwik')
1928
}
2029

2130
include '**/*Properties.class'
2231
include '**/*Test.class'
2332
include '**/*Tests.class'
24-
25-
usesDefaultDistribution()
33+
// explicitly declaring the tasks classpath here. should work out of the box though
34+
classpath = sourceSets.javaRestTest.runtimeClasspath
2635
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.logsdb;
9+
10+
import java.util.HashMap;
11+
import java.util.Map;
12+
13+
public record Mapping(Map<String, Object> mapping) {
14+
15+
public static Mapping generate(Template template) {
16+
var mapping = new HashMap<String, Object>();
17+
18+
var topLevel = new HashMap<String, Object>();
19+
generate(topLevel, template.template());
20+
21+
mapping.put("_doc", Map.of("properties", topLevel));
22+
return new Mapping(mapping);
23+
}
24+
25+
private static void generate(Map<String, Object> mapping, Map<String, Template.Entry> template) {
26+
for (var entry : template.values()) {
27+
if (entry instanceof Template.Leaf l) {
28+
mapping.put(l.name(), Map.of("type", l.type().toString()));
29+
continue;
30+
}
31+
if (entry instanceof Template.Object o) {
32+
var children = new HashMap<String, Object>();
33+
mapping.put(o.name(), Map.of("properties", children));
34+
35+
generate(children, o.children());
36+
}
37+
}
38+
}
39+
}

x-pack/plugin/logsdb/property-rest-tests/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/StandardVsLogsDbRestTest.java

Lines changed: 115 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,33 @@
77

88
package org.elasticsearch.xpack.logsdb;
99

10+
import net.jqwik.api.Arbitrary;
11+
import net.jqwik.api.ForAll;
1012
import net.jqwik.api.Property;
13+
import net.jqwik.api.Provide;
14+
import net.jqwik.api.ShrinkingMode;
1115
import net.jqwik.api.lifecycle.AfterContainer;
16+
import net.jqwik.api.lifecycle.AfterProperty;
1217
import net.jqwik.api.lifecycle.BeforeContainer;
1318

19+
import net.jqwik.api.lifecycle.BeforeProperty;
20+
21+
import org.elasticsearch.client.Request;
22+
import org.elasticsearch.client.Response;
23+
import org.elasticsearch.client.RestClient;
24+
import org.elasticsearch.common.Strings;
1425
import org.elasticsearch.common.logging.LogConfigurator;
26+
import org.elasticsearch.common.settings.Settings;
27+
import org.elasticsearch.rest.RestStatus;
1528
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
29+
import org.elasticsearch.test.rest.ESRestTestCase;
30+
import org.elasticsearch.xcontent.XContentBuilder;
31+
import org.elasticsearch.xcontent.XContentType;
32+
33+
import java.io.IOException;
34+
import java.util.HashSet;
1635

17-
public class StandardVsLogsDbRestTest {
36+
public class StandardVsLogsDbRestTest extends ESRestTestCase {
1837
public static OnDemandLocalCluster cluster = OnDemandClusterBuilder.create()
1938
.distribution(DistributionType.DEFAULT)
2039
.module("data-streams")
@@ -24,6 +43,11 @@ public class StandardVsLogsDbRestTest {
2443
.setting("cluster.logsdb.enabled", "true")
2544
.build();
2645

46+
@Override
47+
protected String getTestRestCluster() {
48+
return cluster.getHttpAddresses();
49+
}
50+
2751
@BeforeContainer
2852
static void beforeContainer() {
2953
LogConfigurator.loadLog4jPlugins();
@@ -33,12 +57,98 @@ static void beforeContainer() {
3357
}
3458

3559
@AfterContainer
36-
static void afterContainer() {
60+
static void afterContainer() throws IOException {
3761
cluster.teardown();
62+
closeClients();
63+
}
64+
65+
@BeforeProperty
66+
void beforeProperty() throws IOException {
67+
initClient();
68+
}
69+
70+
@AfterProperty
71+
void afterProperty() throws Exception {
72+
cleanUpCluster();
73+
}
74+
75+
@Property(shrinking = ShrinkingMode.FULL)
76+
public void testStuff(@ForAll("input") TestInput input) throws IOException {
77+
var mappingXContent = XContentBuilder.builder(XContentType.JSON.xContent());
78+
mappingXContent.map(input.mapping.mapping());
79+
80+
createTemplates(mappingXContent);
81+
createDataStreams();
82+
83+
deleteDataStreams();
84+
deleteTemplates();
85+
86+
}
87+
88+
@Provide
89+
Arbitrary<TestInput> input() {
90+
var template = Template.generate(3, 30);
91+
92+
return template.map(t -> new TestInput(t, Mapping.generate(t)));
93+
}
94+
95+
record TestInput(Template template, Mapping mapping) {
96+
}
97+
98+
private void createTemplates(XContentBuilder mapping) throws IOException {
99+
final Response createBaselineTemplateResponse = createTemplates(
100+
"my-datastream-template",
101+
"my-datastream*",
102+
Settings.builder(),
103+
mapping,
104+
101
105+
);
106+
assert createBaselineTemplateResponse.getStatusLine().getStatusCode() == RestStatus.OK.getStatus();
107+
}
108+
109+
private void createDataStreams() throws IOException {
110+
final Response craeteDataStreamResponse = client().performRequest(
111+
new Request("PUT", "_data_stream/my-datastream")
112+
);
113+
assert craeteDataStreamResponse.getStatusLine().getStatusCode() == RestStatus.OK.getStatus();
114+
}
115+
116+
private Response createTemplates(
117+
final String templateName,
118+
final String pattern,
119+
final Settings.Builder settings,
120+
final XContentBuilder mappings,
121+
int priority
122+
) throws IOException {
123+
final String template = """
124+
{
125+
"index_patterns": [ "%s" ],
126+
"template": {
127+
"settings":%s,
128+
"mappings": %s
129+
},
130+
"data_stream": {},
131+
"priority": %d
132+
}
133+
""";
134+
final Request request = new Request("PUT", "/_index_template/" + templateName);
135+
final String jsonSettings = settings.build().toString();
136+
final String jsonMappings = Strings.toString(mappings);
137+
request.setJsonEntity(Strings.format(template, pattern, jsonSettings, jsonMappings, priority));
138+
return client().performRequest(request);
139+
}
140+
141+
private void deleteDataStreams() throws IOException {
142+
final Response deleteBaselineDataStream = client().performRequest(
143+
new Request("DELETE", "/_data_stream/my-datastream")
144+
);
145+
assert deleteBaselineDataStream.getStatusLine().getStatusCode() == RestStatus.OK.getStatus();
38146
}
39147

40-
@Property
41-
public void testStuff() {
42-
System.out.println("hey");
148+
private void deleteTemplates() throws IOException {
149+
final Response deleteBaselineTemplate = client().performRequest(
150+
new Request("DELETE", "/_index_template/my-datastream-template")
151+
);
152+
assert deleteBaselineTemplate.getStatusLine().getStatusCode() == RestStatus.OK.getStatus();
43153
}
44154
}

0 commit comments

Comments
 (0)