Skip to content

Commit db97e7e

Browse files
authored
Make mvn test pass on Apple silicon (M1) (elastic#2392)
1 parent 1bb6bf5 commit db97e7e

File tree

24 files changed

+159
-41
lines changed

24 files changed

+159
-41
lines changed

apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerClientProxySupportTest.java renamed to apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerClientProxySupportIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
import static org.mockito.Mockito.doReturn;
4949

5050
// Using a separate test class for proxy support
51-
public class ApmServerClientProxySupportTest {
51+
public class ApmServerClientProxySupportIT {
5252

53-
private static final Logger logger = LoggerFactory.getLogger(ApmServerClientProxySupportTest.class);
53+
private static final Logger logger = LoggerFactory.getLogger(ApmServerClientProxySupportIT.class);
5454

5555
private static final String PROXY_HEADER = "proxy-header";
5656
private static final String PROXY_HEADER_VALUE = "1234";
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* 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,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package co.elastic.apm.agent.testutils;
20+
21+
import org.junit.jupiter.api.extension.ExtendWith;
22+
23+
import java.lang.annotation.Documented;
24+
import java.lang.annotation.ElementType;
25+
import java.lang.annotation.Retention;
26+
import java.lang.annotation.RetentionPolicy;
27+
import java.lang.annotation.Target;
28+
29+
@Target({ElementType.TYPE, ElementType.METHOD})
30+
@Retention(RetentionPolicy.RUNTIME)
31+
@Documented
32+
@ExtendWith(DisabledOnAppleSiliconCondition.class)
33+
public @interface DisabledOnAppleSilicon {
34+
35+
/**
36+
* The reason this annotated test class or test method is disabled.
37+
*/
38+
String value() default "";
39+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* 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,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package co.elastic.apm.agent.testutils;
20+
21+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
22+
import org.junit.jupiter.api.extension.ExecutionCondition;
23+
import org.junit.jupiter.api.extension.ExtensionContext;
24+
25+
import java.lang.reflect.AnnotatedElement;
26+
27+
import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled;
28+
import static org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled;
29+
import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation;
30+
31+
public class DisabledOnAppleSiliconCondition implements ExecutionCondition {
32+
33+
@Override
34+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
35+
AnnotatedElement element = context.getElement().orElse(null);
36+
return findAnnotation(element, DisabledOnAppleSilicon.class)
37+
.map(annotation -> isOnAppleSilicon()
38+
? disabled(element + " is @DisabledOnAppleSilicon", annotation.value())
39+
: enabled("Not running on Apple silicon"))
40+
.orElse(enabled("@DisabledOnAppleSilicon is not present"));
41+
}
42+
43+
public boolean isOnAppleSilicon() {
44+
String os = System.getProperty("os.name").toLowerCase();
45+
String arch = System.getProperty("os.arch").toLowerCase();
46+
return os.contains("mac") && arch.contains("aarch");
47+
}
48+
}

apm-agent-core/src/test/resources/log4j2-test.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
<!-- make json validation less verbose -->
1414
<Logger name="com.networknt.schema" level="warn"/>
15+
<Logger name="com.github.dockerjava" level="info"/>
16+
<Logger name="org.testcontainers" level="info"/>
1517

1618
<!-- agent always in debug for easier -->
1719
<Logger name="co.elastic.apm" level="debug"/>

apm-agent-plugins/apm-grpc/apm-grpc-test-latest/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<maven.compiler.target>${maven.compiler.testTarget}</maven.compiler.target>
1919

2020
<grpc.version>[1.29.0,)</grpc.version>
21-
<protobuf.version>3.11.0</protobuf.version>
21+
<protobuf.version>3.19.1</protobuf.version>
2222
</properties>
2323

2424
<build>

apm-agent-plugins/apm-grpc/apm-grpc-test-latest/src/test/java/co/elastic/apm/agent/grpc/latest/testapp/generated/HelloReply.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Protobuf type {@code helloworld.HelloReply}
2626
*/
27-
public final class HelloReply extends
27+
public final class HelloReply extends
2828
com.google.protobuf.GeneratedMessageV3 implements
2929
// @@protoc_insertion_point(message_implements:helloworld.HelloReply)
3030
HelloReplyOrBuilder {
@@ -111,6 +111,7 @@ private HelloReply(
111111
* <code>string message = 1;</code>
112112
* @return The message.
113113
*/
114+
@java.lang.Override
114115
public java.lang.String getMessage() {
115116
java.lang.Object ref = message_;
116117
if (ref instanceof java.lang.String) {
@@ -127,6 +128,7 @@ public java.lang.String getMessage() {
127128
* <code>string message = 1;</code>
128129
* @return The bytes for message.
129130
*/
131+
@java.lang.Override
130132
public com.google.protobuf.ByteString
131133
getMessageBytes() {
132134
java.lang.Object ref = message_;
@@ -155,7 +157,7 @@ public final boolean isInitialized() {
155157
@java.lang.Override
156158
public void writeTo(com.google.protobuf.CodedOutputStream output)
157159
throws java.io.IOException {
158-
if (!getMessageBytes().isEmpty()) {
160+
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(message_)) {
159161
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, message_);
160162
}
161163
unknownFields.writeTo(output);
@@ -167,7 +169,7 @@ public int getSerializedSize() {
167169
if (size != -1) return size;
168170

169171
size = 0;
170-
if (!getMessageBytes().isEmpty()) {
172+
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(message_)) {
171173
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, message_);
172174
}
173175
size += unknownFields.getSerializedSize();

apm-agent-plugins/apm-grpc/apm-grpc-test-latest/src/test/java/co/elastic/apm/agent/grpc/latest/testapp/generated/HelloRequest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Protobuf type {@code helloworld.HelloRequest}
2626
*/
27-
public final class HelloRequest extends
27+
public final class HelloRequest extends
2828
com.google.protobuf.GeneratedMessageV3 implements
2929
// @@protoc_insertion_point(message_implements:helloworld.HelloRequest)
3030
HelloRequestOrBuilder {
@@ -116,6 +116,7 @@ private HelloRequest(
116116
* <code>string userName = 1;</code>
117117
* @return The userName.
118118
*/
119+
@java.lang.Override
119120
public java.lang.String getUserName() {
120121
java.lang.Object ref = userName_;
121122
if (ref instanceof java.lang.String) {
@@ -132,6 +133,7 @@ public java.lang.String getUserName() {
132133
* <code>string userName = 1;</code>
133134
* @return The bytes for userName.
134135
*/
136+
@java.lang.Override
135137
public com.google.protobuf.ByteString
136138
getUserNameBytes() {
137139
java.lang.Object ref = userName_;
@@ -152,6 +154,7 @@ public java.lang.String getUserName() {
152154
* <code>int32 depth = 2;</code>
153155
* @return The depth.
154156
*/
157+
@java.lang.Override
155158
public int getDepth() {
156159
return depth_;
157160
}
@@ -170,7 +173,7 @@ public final boolean isInitialized() {
170173
@java.lang.Override
171174
public void writeTo(com.google.protobuf.CodedOutputStream output)
172175
throws java.io.IOException {
173-
if (!getUserNameBytes().isEmpty()) {
176+
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(userName_)) {
174177
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, userName_);
175178
}
176179
if (depth_ != 0) {
@@ -185,7 +188,7 @@ public int getSerializedSize() {
185188
if (size != -1) return size;
186189

187190
size = 0;
188-
if (!getUserNameBytes().isEmpty()) {
191+
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(userName_)) {
189192
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, userName_);
190193
}
191194
if (depth_ != 0) {
@@ -556,6 +559,7 @@ public Builder setUserNameBytes(
556559
* <code>int32 depth = 2;</code>
557560
* @return The depth.
558561
*/
562+
@java.lang.Override
559563
public int getDepth() {
560564
return depth_;
561565
}

apm-agent-plugins/apm-grpc/pom.xml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@
2121
<protobuf.version>should-be-set-at-module-level</protobuf.version>
2222
</properties>
2323

24-
<modules>
25-
<module>apm-grpc-plugin</module>
26-
<module>apm-grpc-test-1.6.1</module>
27-
<!-- other intermediate gRPC versions that have been tested : 1.7.1, 1,9.1, 1.13.2, 1.22.0, 1.23.0, 1.27.1 -->
28-
<module>apm-grpc-test-latest</module>
29-
</modules>
30-
3124
<build>
3225
<plugins>
3326
<plugin>
@@ -46,6 +39,35 @@
4639
</build>
4740

4841
<profiles>
42+
<profile>
43+
<id>default</id>
44+
<activation>
45+
<activeByDefault>true</activeByDefault>
46+
</activation>
47+
<modules>
48+
<module>apm-grpc-plugin</module>
49+
<module>apm-grpc-test-1.6.1</module>
50+
<!-- other intermediate gRPC versions that have been tested : 1.7.1, 1,9.1, 1.13.2, 1.22.0, 1.23.0, 1.27.1 -->
51+
<module>apm-grpc-test-latest</module>
52+
</modules>
53+
</profile>
54+
<profile>
55+
<!--
56+
Old grpc/protobuf compilers don't support mac aarch64 (Apple Silicon, such as M1)
57+
Therefore, excluding apm-grpc-test-1.6.1
58+
-->
59+
<id>apple-silicon</id>
60+
<activation>
61+
<os>
62+
<family>mac</family>
63+
<arch>aarch64</arch>
64+
</os>
65+
</activation>
66+
<modules>
67+
<module>apm-grpc-plugin</module>
68+
<module>apm-grpc-test-latest</module>
69+
</modules>
70+
</profile>
4971
<profile>
5072
<id>update-grpc</id>
5173
<activation>

apm-agent-plugins/apm-jdbc-plugin/src/test/java/co/elastic/apm/agent/jdbc/AbstractJdbcInstrumentationTest.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,8 @@ private void testBatchPreparedStatement(boolean isLargeBatch) throws SQLExceptio
385385
System.arraycopy(batchUpdates, 0, updates, 0, batchUpdates.length);
386386
}
387387

388-
long expectedAffected = 2;
389-
if (isKnownDatabase("Oracle", "")) {
390-
// for an unknown reason Oracle express have unexpected but somehow consistent behavior here
391-
assertThat(updates).containsExactly(-2, -2);
392-
expectedAffected = -4;
393-
} else {
394-
assertThat(updates).containsExactly(1, 1);
395-
}
396-
397-
assertSpanRecorded(query, false, expectedAffected);
388+
assertThat(updates).containsExactly(1, 1);
389+
assertSpanRecorded(query, false, 2);
398390
}
399391

400392
private void testMultipleRowsModifiedStatement() throws SQLException {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
oracle.container.image=wnameless/oracle-xe-11g-r2:latest
1+
oracle.container.image=gvenzl/oracle-xe:slim

0 commit comments

Comments
 (0)