Skip to content

Commit

Permalink
Merge branch 'apache:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hyz1994121 authored Mar 16, 2023
2 parents 0369c3c + 43bdccb commit 1193156
Show file tree
Hide file tree
Showing 1,166 changed files with 13,882 additions and 8,024 deletions.
23 changes: 7 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ env:

jobs:
ci:
name: CI - JDK ${{ matrix.java-version }} on ${{ matrix.os }}
name: CI - on JDK ${{ matrix.java-version }}
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
Expand All @@ -78,18 +78,16 @@ jobs:
run: ./mvnw -T1C -B -ntp clean install
- name: Build examples with Maven
run: ./mvnw -T1C -B -f examples/pom.xml clean package -DskipTests
- name: Setup JDK 8 for Test
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
- name: Run tests with JDK 8
- name: Run tests with JDK ${{ matrix.java-version }}
run: ./mvnw -T1C -B -ntp -fae test

test-coverage:
if: github.repository == 'apache/shardingsphere'
name: Test coverage report
name: Test coverage report on JDK ${{ matrix.java-version }}
runs-on: ubuntu-latest
strategy:
matrix:
java-version: [ 11, 19 ]
steps:
- uses: actions/checkout@v3
- name: Cache Maven Repos
Expand All @@ -102,15 +100,8 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 11
java-version: ${{ matrix.java-version }}
- name: Build with Maven
run: ./mvnw -T1C -B -ntp clean install -DskipTests
- name: Setup JDK 8 for Test
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
- name: Test with Maven
run: ./mvnw -T1C -B -ntp test cobertura:cobertura -Djacoco.skip=false
- name: Upload to Codecov
run: bash <(curl -s https://codecov.io/bash)
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
name: single rule
needs: it-empty-rule
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 15
strategy:
matrix:
adapter: [ proxy, jdbc ]
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/nightly-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,39 @@ jobs:
run: ./mvnw -T1C -B -ntp clean install
- name: Build examples with Maven
run: ./mvnw -T1C -B -f examples/pom.xml clean package

ci-jdk8:
if: github.repository == 'apache/shardingsphere'
name: CI - JDK 8 on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 90
strategy:
max-parallel: 1
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
steps:
- name: Support long paths in Windows
if: matrix.os == 'windows-latest'
run: git config --global core.longpaths true
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 11
- uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ env.REPOSITORY_NAME }}-maven-third-party-cache-${{ github.sha }}
restore-keys: |
${{ env.REPOSITORY_NAME }}-maven-third-party-cache-
${{ env.REPOSITORY_NAME }}-maven-third-party-
- name: Build prod with Maven
run: ./mvnw -T1C -B -ntp clean install
- name: Setup JDK 8 for Test
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
- name: Run tests with JDK 8
run: ./mvnw -T1C -B -ntp -fae test
2 changes: 1 addition & 1 deletion .github/workflows/nightly-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
name: single rule
needs: it-empty-rule
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 15
strategy:
max-parallel: 2
fail-fast: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.agent.core.advisor.config.yaml.entity.YamlAdvisorsConfiguration;
import org.yaml.snakeyaml.Yaml;
import org.apache.shardingsphere.agent.core.yaml.AgentYamlEngine;

import java.io.InputStream;

Expand All @@ -37,7 +37,7 @@ public final class YamlAdvisorsConfigurationLoader {
* @return loaded advisors configuration
*/
public static YamlAdvisorsConfiguration load(final InputStream inputStream) {
YamlAdvisorsConfiguration result = new Yaml().loadAs(inputStream, YamlAdvisorsConfiguration.class);
YamlAdvisorsConfiguration result = AgentYamlEngine.unmarshalYamlAdvisorsConfiguration(inputStream);
return null == result ? new YamlAdvisorsConfiguration() : result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.agent.core.plugin.config.yaml.entity.YamlAgentConfiguration;
import org.apache.shardingsphere.agent.core.yaml.AgentYamlConstructor;
import org.apache.shardingsphere.agent.core.yaml.AgentYamlEngine;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Optional;

/**
Expand All @@ -42,10 +43,9 @@ public final class YamlPluginConfigurationLoader {
* @throws IOException IO exception
*/
public static Optional<YamlAgentConfiguration> load(final File yamlFile) throws IOException {
try (
FileInputStream fileInputStream = new FileInputStream(yamlFile);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream)) {
YamlAgentConfiguration result = new Yaml().loadAs(inputStreamReader, YamlAgentConfiguration.class);
Yaml yaml = new Yaml(new AgentYamlConstructor(YamlAgentConfiguration.class));
try (FileInputStream fileInputStream = new FileInputStream(yamlFile)) {
YamlAgentConfiguration result = AgentYamlEngine.unmarshalYamlAgentConfiguration(fileInputStream);
return null == result ? Optional.empty() : Optional.of(result);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.agent.core.yaml;

import com.google.common.base.Preconditions;
import org.yaml.snakeyaml.constructor.Constructor;

/**
* Agent YAML constructor.
*/
public final class AgentYamlConstructor extends Constructor {

private final Class<?> rootClass;

public AgentYamlConstructor(final Class<?> rootClass) {
super(rootClass);
this.rootClass = rootClass;
}

@Override
protected Class<?> getClassForName(final String className) throws ClassNotFoundException {
Preconditions.checkArgument(className.equals(rootClass.getName()), "Class `%s` is not accepted", className);
return super.getClassForName(className);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.agent.core.yaml;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.agent.core.advisor.config.yaml.entity.YamlAdvisorsConfiguration;
import org.apache.shardingsphere.agent.core.plugin.config.yaml.entity.YamlAgentConfiguration;
import org.yaml.snakeyaml.Yaml;

import java.io.IOException;
import java.io.InputStream;

/**
* Agent YAML engine.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class AgentYamlEngine {

/**
* Unmarshal YAML agent configuration YAML.
*
* @param inputStream input stream
* @return YAML agent configuration
* @throws IOException IO Exception
*/
public static YamlAgentConfiguration unmarshalYamlAgentConfiguration(final InputStream inputStream) {
return new Yaml(new AgentYamlConstructor(YamlAgentConfiguration.class)).loadAs(inputStream, YamlAgentConfiguration.class);
}

/**
* Unmarshal YAML advisors configuration YAML.
*
* @param inputStream input stream
* @return YAML advisors configuration
* @throws IOException IO Exception
*/
public static YamlAdvisorsConfiguration unmarshalYamlAdvisorsConfiguration(final InputStream inputStream) {
return new Yaml(new AgentYamlConstructor(YamlAdvisorsConfiguration.class)).loadAs(inputStream, YamlAdvisorsConfiguration.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import net.bytebuddy.matcher.ElementMatchers;
import org.apache.shardingsphere.agent.core.advisor.config.AdvisorConfiguration;
import org.apache.shardingsphere.agent.core.advisor.config.MethodAdvisorConfiguration;
import org.apache.shardingsphere.agent.core.advisor.config.yaml.entity.YamlAdvisorsConfiguration;
import org.apache.shardingsphere.agent.core.advisor.config.yaml.fixture.YamlAdviceFixture;
import org.apache.shardingsphere.agent.core.advisor.config.yaml.fixture.YamlTargetObjectFixture;
import org.apache.shardingsphere.agent.core.yaml.AgentYamlEngine;
import org.junit.jupiter.api.Test;
import org.yaml.snakeyaml.Yaml;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -38,7 +37,7 @@ public final class YamlAdvisorsConfigurationSwapperTest {
@Test
public void assertSwapToObject() {
Collection<AdvisorConfiguration> actual = YamlAdvisorsConfigurationSwapper.swap(
new Yaml().loadAs(getClass().getResourceAsStream("/META-INF/conf/advisors.yaml"), YamlAdvisorsConfiguration.class), "FIXTURE");
AgentYamlEngine.unmarshalYamlAdvisorsConfiguration(getClass().getResourceAsStream("/META-INF/conf/advisors.yaml")), "FIXTURE");
assertThat(actual.size(), is(1));
assertAdvisorConfiguration(actual.iterator().next());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
import org.apache.shardingsphere.agent.core.plugin.config.yaml.entity.YamlAgentConfiguration;
import org.apache.shardingsphere.agent.core.plugin.config.yaml.entity.YamlPluginCategoryConfiguration;
import org.apache.shardingsphere.agent.core.plugin.config.yaml.entity.YamlPluginConfiguration;
import org.apache.shardingsphere.agent.core.yaml.AgentYamlEngine;
import org.junit.jupiter.api.Test;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Collections;
Expand Down Expand Up @@ -82,7 +81,7 @@ public void assertSwapWithMultiplePluginConfigurations() {

@Test
public void assertSwapWithFile() throws IOException {
YamlAgentConfiguration yamlAgentConfig = new Yaml().loadAs(new InputStreamReader(new FileInputStream(new File(getResourceURL(), CONFIG_PATH))), YamlAgentConfiguration.class);
YamlAgentConfiguration yamlAgentConfig = AgentYamlEngine.unmarshalYamlAgentConfiguration(new FileInputStream(new File(getResourceURL(), CONFIG_PATH)));
Map<String, PluginConfiguration> actual = YamlPluginsConfigurationSwapper.swap(yamlAgentConfig);
assertThat(actual.size(), is(3));
assertLogFixturePluginConfiguration(actual.get("log_fixture"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.agent.core.plugin.jar;

import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Collection;
import java.util.Objects;
import java.util.jar.JarFile;

import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class PluginJarLoaderTest {

@Test
public void assertLoad() throws IOException {
Collection<JarFile> jarFiles = PluginJarLoader.load(new File(getResourceURL()));
assertThat(jarFiles.size(), is(1));
assertThat(jarFiles.iterator().next().getName(), endsWith("test-plugin.jar"));
}

private String getResourceURL() throws UnsupportedEncodingException {
return URLDecoder.decode(
Objects.requireNonNull(PluginJarLoader.class.getClassLoader().getResource(""))
.getFile(),
"UTF8");
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
import java.util.Collection;
import java.util.HashSet;

public final class AgentExtension implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback {
/**
* Tracing agent extension.
*/
public final class TracingAgentExtension implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback {

private static final String EXTRA_DATA = "_$EXTRA_DATA$_";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import lombok.Getter;
import lombok.SneakyThrows;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.tracing.AgentExtension;
import org.apache.shardingsphere.agent.plugin.tracing.TracingAgentExtension;
import org.apache.shardingsphere.agent.plugin.tracing.MockDataSourceMetaData;
import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
Expand All @@ -43,7 +43,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@ExtendWith(AgentExtension.class)
@ExtendWith(TracingAgentExtension.class)
public abstract class AbstractJDBCExecutorCallbackAdviceTest implements AdviceTestBase {

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

import lombok.Getter;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.plugin.tracing.AgentExtension;
import org.apache.shardingsphere.agent.plugin.tracing.TracingAgentExtension;
import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.mockito.Mockito.mock;

@ExtendWith(AgentExtension.class)
@ExtendWith(TracingAgentExtension.class)
public abstract class AbstractSQLParserEngineAdviceTest implements AdviceTestBase {

@Getter
Expand Down
Loading

0 comments on commit 1193156

Please sign in to comment.