Skip to content

Commit

Permalink
CDPD-29746: Don't publish test artifacts
Browse files Browse the repository at this point in the history
Change-Id: I4a8a1370d0a3ebf44669ba6778e7552d71b8f33f
  • Loading branch information
Andras Csaki committed Oct 1, 2022
1 parent ff4f00e commit f17bb8a
Show file tree
Hide file tree
Showing 17 changed files with 839 additions and 47 deletions.
23 changes: 10 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,6 @@ subprojects {
test.finalizedBy(jacocoTestReport)
jacocoTestReport.dependsOn(test)

task testJar(type: Jar, dependsOn: testClasses) {
classifier = 'test'
from sourceSets.test.output
}

artifacts {
tests testJar
}

checkstyle {
toolVersion = '9.3'
ignoreFailures = false
Expand Down Expand Up @@ -155,15 +146,21 @@ subprojects {
}
}

if (it.name != 'jersey-shaded') { // jersey-shaded has custom publication
configurations.matching { it.name.contains("tests") }.each {testConfiguration ->
try {
components.java.withVariantsFromConfiguration(testConfiguration) {
skip()
}
} catch(InvalidUserDataException e) {}
}

// jersey-shaded has custom publication and we don't publish any test artifacts
if (it.name != 'jersey-shaded' & it.name != 'behavior-tests') {
publishing {
publications {
mavenJava(MavenPublication) {
groupId = group
from components.java
artifact(testJar) {
classifier "tests"
}
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions examples/schema-registry/schema-lifecycle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,4 @@ dependencies {
testImplementation group: 'org.scala-lang', name: 'scala-reflect', version: scala_version

testCompile libraries.junit
testCompile(project(path: ':schema-registry:schema-registry-webservice', configuration: 'tests')) {
exclude group: 'junit'
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,88 @@

package com.hortonworks.registries.examples.schema.lifecycle;

import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient;
import com.hortonworks.registries.schemaregistry.webservice.LocalSchemaRegistryServer;
import org.apache.commons.io.IOUtils;
import org.yaml.snakeyaml.Yaml;

import java.io.FileInputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

public class SchemaLifecycleApp {

private static LocalSchemaRegistryServer LOCAL_SCHEMA_REGISTRY_SERVER = null;
private LocalSchemaRegistryServer localSchemaRegistryServer;
private volatile Map<String, Object> cachedClientConf;
private volatile SchemaRegistryClient cachedSchemaRegistryClient;
private static final String V1_API_PATH = "api/v1";

private final String serverConfigurationPath;

public static void main(String[] args) throws Exception {
startUp();
public SchemaLifecycleApp(String serverConfigurationPath) {
this.serverConfigurationPath = serverConfigurationPath;
}

public static void startUp() throws Exception {
LOCAL_SCHEMA_REGISTRY_SERVER = new LocalSchemaRegistryServer(SchemaLifecycleApp.class.getClassLoader()
public SchemaLifecycleApp() {
this(SchemaLifecycleApp.class.getClassLoader()
.getResource("registry-lifecycle-example.yaml").getPath());
LOCAL_SCHEMA_REGISTRY_SERVER.start();
}

private SchemaLifecycleApp() { }
public void startUp() throws Exception {
localSchemaRegistryServer = new LocalSchemaRegistryServer(serverConfigurationPath);
localSchemaRegistryServer.start();
}

public void stop() throws Exception {
localSchemaRegistryServer.stop();
}

public SchemaRegistryClient getClient() {
return getClient(null);
}

public SchemaRegistryClient getClient(String clientConfigPath) {
SchemaRegistryClient schemaRegistryClient = new SchemaRegistryClient(exportClientConf(false, clientConfigPath));
if (cachedSchemaRegistryClient == null) {
cachedSchemaRegistryClient = schemaRegistryClient;
}
return schemaRegistryClient;
}

private Map<String, Object> exportClientConf(boolean cached, String clientConfigPath) {
if (!cached) {
Map<String, Object> clientConfig = createClientConf(clientConfigPath);
if (cachedClientConf == null) {
cachedClientConf = clientConfig;
}
return clientConfig;
} else {
if (cachedClientConf == null) {
cachedClientConf = createClientConf(clientConfigPath);
}
return cachedClientConf;
}
}

private Map<String, Object> createClientConf(String clientConfigPath) {
String registryURL = getRegistryURL();
if (clientConfigPath == null) {
Map<String, Object> ret = new HashMap<>();
ret.put(SchemaRegistryClient.Configuration.SCHEMA_REGISTRY_URL.name(), registryURL);
return ret;
}
try (FileInputStream fis = new FileInputStream(clientConfigPath)) {
Map<String, Object> ret = new Yaml().load(IOUtils.toString(fis, StandardCharsets.UTF_8));
ret.put("schema.registry.url", registryURL);
return ret;
} catch (Exception e) {
throw new RuntimeException("Failed to export schema client configuration for yaml : " +
clientConfigPath, e);
}
}

private String getRegistryURL() {
return localSchemaRegistryServer.getLocalURL() + V1_API_PATH;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
import com.hortonworks.registries.schemaregistry.SchemaVersion;
import com.hortonworks.registries.schemaregistry.SchemaVersionInfo;
import com.hortonworks.registries.schemaregistry.avro.AvroSchemaProvider;
import com.hortonworks.registries.schemaregistry.avro.conf.SchemaRegistryTestConfiguration;
import com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper;
import com.hortonworks.registries.schemaregistry.avro.util.AvroSchemaRegistryClientUtil;
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient;
import com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException;
import com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException;
Expand All @@ -47,27 +44,26 @@ public class CustomStateTransitionTest {

private static final Logger LOG = LoggerFactory.getLogger(CustomStateTransitionTest.class);

private SchemaRegistryTestServerClientWrapper schemaRegistryTestServerClientWrapper;
private SchemaLifecycleApp schemaRegistryTestServer;
private SchemaRegistryClient schemaRegistryClient;

@BeforeEach
public void startUp() throws Exception {
String serverYAMLPath = CustomStateTransitionTest.class.getClassLoader().getResource("registry-lifecycle-test-example.yaml").getPath();
String clientYAMLPath = CustomStateTransitionTest.class.getClassLoader().getResource("registry-lifecycle-client.yaml").getPath();
schemaRegistryTestServerClientWrapper = new SchemaRegistryTestServerClientWrapper(new SchemaRegistryTestConfiguration(serverYAMLPath,
clientYAMLPath));
schemaRegistryTestServerClientWrapper.startTestServer();
schemaRegistryClient = schemaRegistryTestServerClientWrapper.getClient();
schemaRegistryTestServer = new SchemaLifecycleApp(serverYAMLPath);
schemaRegistryTestServer.startUp();
schemaRegistryClient = schemaRegistryTestServer.getClient(clientYAMLPath);
}

@AfterEach
public void tearDown() throws Exception {
schemaRegistryTestServerClientWrapper.stopTestServer();
schemaRegistryTestServer.stop();
}

@Test
public void testTransitionToRejectedState()
throws IOException, SchemaNotFoundException, InvalidSchemaException, IncompatibleSchemaException,
public void testTransitionToRejectedState()
throws IOException, SchemaNotFoundException, InvalidSchemaException, IncompatibleSchemaException,
SchemaBranchAlreadyExistsException, SchemaLifecycleException {
SchemaMetadata schemaMetadata = createSchemaMetadata("test", SchemaCompatibility.NONE);
SchemaBranch branch1 = new SchemaBranch("BRANCH1", schemaMetadata.getName());
Expand All @@ -81,13 +77,13 @@ public void testTransitionToRejectedState()

schemaRegistryClient.createSchemaBranch(schemaIdVersion1.getSchemaVersionId(), branch1);

String schema2 = AvroSchemaRegistryClientUtil.getSchema("/device1.avsc");
String schema2 = getSchema("/device1.avsc");
LOG.info("Creating second version for the schema \"{}\"", schemaMetadata.getName());
SchemaIdVersion schemaIdVersion2 = schemaRegistryClient
.addSchemaVersion(branch1.getName(), schemaMetadata, new SchemaVersion(schema2, "modify version"));
LOG.info("ID of the second version is {}", schemaIdVersion2);

LOG.info("Starting review of the second version with ID {} (new state: {})",
LOG.info("Starting review of the second version with ID {} (new state: {})",
schemaIdVersion2.getSchemaVersionId(), CustomReviewCycleStates.PEER_REVIEW_STATE.getId());
schemaRegistryClient.startSchemaVersionReview(schemaIdVersion2.getSchemaVersionId());
SchemaVersionInfo schemaVersionInfoAtReviewState = schemaRegistryClient
Expand All @@ -96,7 +92,7 @@ public void testTransitionToRejectedState()
Assertions.assertEquals(CustomReviewCycleStates.PEER_REVIEW_STATE.getId(), schemaVersionInfoAtReviewState.getStateId());

LOG.info("Transitioning second version into REJECTED ({}) state.", CustomReviewCycleStates.REJECTED_REVIEW_STATE.getId());
schemaRegistryClient.transitionState(schemaIdVersion2.getSchemaVersionId(),
schemaRegistryClient.transitionState(schemaIdVersion2.getSchemaVersionId(),
CustomReviewCycleStates.REJECTED_REVIEW_STATE.getId(), "Rejected by X".getBytes());
SchemaVersionInfo schemaVersionInfoAtRejectedState = schemaRegistryClient
.getSchemaVersionInfo(new SchemaIdVersion(schemaIdVersion2.getSchemaVersionId()));
Expand Down
9 changes: 3 additions & 6 deletions schema-registry/schema-registry-webservice/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ dependencies {
}
}

testCompile(project(path: ':schema-registry:schema-registry-client', configuration: 'tests')) { transitive = false }
testCompile(project(path: ':schema-registry:schema-registry-serdes', configuration: 'tests')) { transitive = false }
testCompile project(path: ':schema-registry:schema-registry-common', configuration: 'tests')
testCompile project(path: ':schema-registry:schema-registry-core', configuration: 'tests')
testCompile project(path: ':registry-common', configuration: 'tests')
testCompile(project(path: ':schema-registry:schema-registry-client')) { transitive = false }
testCompile(project(path: ':schema-registry:schema-registry-serdes')) { transitive = false }

testCompile libraries.junit
testCompile libraries.mockito
Expand All @@ -95,7 +92,7 @@ dependencies {
testCompile libraries.kafka.test.clients
testCompile libraries.kafka.test.streams
testCompile libraries.kafka.test.streams_test_utils

testCompile(libraries.kafka.test.core) { exclude group: 'org.scala-lang' }
testCompile(libraries.kafka.core) { exclude group: 'org.scala-lang' }

Expand Down
Loading

0 comments on commit f17bb8a

Please sign in to comment.