-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from ligangty/o11y
Add two unit tests
- Loading branch information
Showing
17 changed files
with
291 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...-java/src/main/java/org/commonjava/indy/client/core/o11y/metric/RequestContextHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
core-java/src/main/java/org/commonjava/indy/client/core/o11y/trace/NameUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
core-java/src/main/java/org/commonjava/indy/client/core/o11y/trace/OtelProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
core-java/src/main/java/org/commonjava/indy/client/core/o11y/trace/SpanClosingResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
core-java/src/main/java/org/commonjava/indy/client/core/o11y/trace/SpanProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
core-java/src/main/java/org/commonjava/indy/client/core/o11y/trace/SpanWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
core-java/src/main/java/org/commonjava/indy/client/core/o11y/trace/SpanningHttpFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
core-java/src/main/java/org/commonjava/indy/client/core/o11y/trace/TraceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
core-java/src/main/java/org/commonjava/indy/client/core/o11y/trace/TracerHttpClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
core-java/src/main/java/org/commonjava/indy/client/core/util/ThreadContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
core-java/src/test/java/org/commonjava/indy/client/core/AbstractIndyClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/** | ||
* Copyright (C) 2023 Red Hat, Inc. (https://github.com/Commonjava/indy-client) | ||
* | ||
* Licensed 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.commonjava.indy.client.core; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.commonjava.indy.client.core.module.IndyStoreQueryClientModule; | ||
import org.commonjava.indy.client.core.module.IndyStoresClientModule; | ||
import org.commonjava.indy.client.core.util.UrlUtils; | ||
import org.commonjava.indy.model.core.Group; | ||
import org.commonjava.indy.model.core.HostedRepository; | ||
import org.commonjava.indy.model.core.RemoteRepository; | ||
import org.commonjava.indy.model.core.StoreKey; | ||
import org.commonjava.indy.model.core.StoreType; | ||
import org.commonjava.indy.model.core.io.IndyObjectMapper; | ||
import org.commonjava.test.http.expect.ExpectationServer; | ||
import org.commonjava.util.jhttpc.model.SiteConfig; | ||
import org.commonjava.util.jhttpc.model.SiteConfigBuilder; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.nio.charset.Charset; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import static org.commonjava.indy.client.core.util.UrlUtils.normalizePath; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public abstract class AbstractIndyClientTest | ||
{ | ||
private static final String BASE_STORE_PATH = "/api/admin/stores"; | ||
|
||
@Rule | ||
public ExpectationServer server = new ExpectationServer(); | ||
|
||
private final IndyObjectMapper mapper = new IndyObjectMapper( false ); | ||
|
||
private Indy client; | ||
|
||
@Before | ||
public void setUp() | ||
{ | ||
final String serviceUrl = UrlUtils.buildUrl( server.getBaseUri(), "api" ); | ||
|
||
SiteConfig config = new SiteConfigBuilder( "indy", serviceUrl ).withRequestTimeoutSeconds( 30 ) | ||
.withMetricEnabled( false ) | ||
.build(); | ||
Collection<IndyClientModule> modules = | ||
Arrays.asList( new IndyStoresClientModule(), new IndyStoreQueryClientModule() ); | ||
|
||
client = getClient( config, modules ); | ||
} | ||
|
||
protected abstract Indy getClient(SiteConfig siteConfig, Collection<IndyClientModule> modules); | ||
|
||
@Test | ||
public void testGetStores() | ||
throws Exception | ||
{ | ||
String path = normalizePath( BASE_STORE_PATH, "maven/remote/central" ); | ||
server.expect( path, 200, readResource( "repo-service/remote-central.json" ) ); | ||
StoreKey key = StoreKey.fromString( "maven:remote:central" ); | ||
RemoteRepository remote = client.module( IndyStoresClientModule.class ).load( key, RemoteRepository.class ); | ||
assertNotNull( remote ); | ||
assertThat( remote.getKey(), equalTo( key ) ); | ||
assertThat( remote.getType(), equalTo( StoreType.remote ) ); | ||
|
||
path = normalizePath( BASE_STORE_PATH, "maven/hosted/local-deployments" ); | ||
server.expect( path, 200, readResource( "repo-service/hosted-localdeploy.json" ) ); | ||
key = StoreKey.fromString( "maven:hosted:local-deployments" ); | ||
HostedRepository hosted = client.module( IndyStoresClientModule.class ).load( key, HostedRepository.class ); | ||
assertNotNull( hosted ); | ||
assertThat( hosted.getKey(), equalTo( key ) ); | ||
assertThat( hosted.getType(), equalTo( StoreType.hosted ) ); | ||
|
||
path = normalizePath( BASE_STORE_PATH, "maven/group/static" ); | ||
server.expect( path, 200, readResource( "repo-service/group-static.json" ) ); | ||
key = StoreKey.fromString( "maven:group:static" ); | ||
Group group = client.module( IndyStoresClientModule.class ).load( key, Group.class ); | ||
assertNotNull( group ); | ||
assertThat( group.getKey(), equalTo( key ) ); | ||
assertThat( group.getType(), equalTo( StoreType.group ) ); | ||
} | ||
|
||
static String readResource( final String resourcePath ) | ||
throws IOException | ||
{ | ||
URL url = Thread.currentThread().getContextClassLoader().getResource( resourcePath ); | ||
if ( url != null ) | ||
{ | ||
return IOUtils.toString( url.openStream(), Charset.defaultCharset() ); | ||
} | ||
throw new IOException( String.format( "File not exists: %s", resourcePath ) ); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
core-java/src/test/java/org/commonjava/indy/client/core/IndyClientWithTraceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright (C) 2023 Red Hat, Inc. (https://github.com/Commonjava/indy-client) | ||
* | ||
* Licensed 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.commonjava.indy.client.core; | ||
|
||
import org.commonjava.indy.client.core.o11y.trace.ClientTracerConfiguration; | ||
import org.commonjava.indy.model.core.io.IndyObjectMapper; | ||
import org.commonjava.util.jhttpc.auth.MemoryPasswordManager; | ||
import org.commonjava.util.jhttpc.model.SiteConfig; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
public class IndyClientWithTraceTest | ||
extends AbstractIndyClientTest | ||
{ | ||
|
||
@Override | ||
protected Indy getClient( SiteConfig siteConfig, Collection<IndyClientModule> modules ) | ||
{ | ||
try | ||
{ | ||
|
||
final Indy.Builder builder = Indy.builder() | ||
.setLocation( siteConfig ) | ||
.setObjectMapper( new IndyObjectMapper( Collections.emptySet() ) ) | ||
.setMdcCopyMappings( Collections.emptyMap() ) | ||
.setModules( modules.toArray( new IndyClientModule[0] ) ); | ||
|
||
ClientTracerConfiguration clientTracerConfig = new ClientTracerConfiguration(); | ||
clientTracerConfig.setEnabled( true ); | ||
clientTracerConfig.setConsoleTransport( true ); | ||
builder.setTraceConfiguration( clientTracerConfig ); | ||
builder.setPasswordManager( new MemoryPasswordManager() ); | ||
|
||
return builder.build(); | ||
} | ||
catch ( IndyClientException e ) | ||
{ | ||
throw new RuntimeException( e ); | ||
} | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
core-java/src/test/java/org/commonjava/indy/client/core/IndyClientWithoutTraceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (C) 2023 Red Hat, Inc. (https://github.com/Commonjava/indy-client) | ||
* | ||
* Licensed 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.commonjava.indy.client.core; | ||
|
||
import org.commonjava.indy.model.core.io.IndyObjectMapper; | ||
import org.commonjava.util.jhttpc.auth.MemoryPasswordManager; | ||
import org.commonjava.util.jhttpc.model.SiteConfig; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
public class IndyClientWithoutTraceTest | ||
extends AbstractIndyClientTest | ||
{ | ||
@Override | ||
protected Indy getClient( SiteConfig siteConfig, Collection<IndyClientModule> modules ) | ||
{ | ||
try | ||
{ | ||
|
||
final Indy.Builder builder = Indy.builder() | ||
.setLocation( siteConfig ) | ||
.setObjectMapper( new IndyObjectMapper( Collections.emptySet() ) ) | ||
.setMdcCopyMappings( Collections.emptyMap() ) | ||
.setModules( modules.toArray( new IndyClientModule[0] ) ); | ||
builder.setPasswordManager( new MemoryPasswordManager() ); | ||
return builder.build(); | ||
} | ||
catch ( IndyClientException e ) | ||
{ | ||
throw new RuntimeException( e ); | ||
} | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
core-java/src/test/resources/repo-service/group-static.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"type" : "group", | ||
"key" : "maven:group:static", | ||
"description" : "This group provides faster access to static data, that are stored in Indy.", | ||
"metadata" : { | ||
"changelog" : "" | ||
}, | ||
"disabled" : false, | ||
"constituents" : [ "maven:group:builds-untested+shared-imports" ], | ||
"name" : "static", | ||
"packageType" : "maven", | ||
"disable_timeout" : -1, | ||
"path_style" : "plain", | ||
"authoritative_index" : false, | ||
"create_time" : "2019-12-12 21:06:58 +0000", | ||
"prepend_constituent" : false | ||
} |
15 changes: 15 additions & 0 deletions
15
core-java/src/test/resources/repo-service/hosted-localdeploy.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"type" : "hosted", | ||
"key" : "maven:hosted:local-deployments", | ||
"disabled" : false, | ||
"snapshotTimeoutSeconds" : 86400, | ||
"readonly" : false, | ||
"name" : "local-deployments", | ||
"packageType" : "maven", | ||
"disable_timeout" : 0, | ||
"path_style" : "plain", | ||
"authoritative_index" : false, | ||
"create_time" : "2022-06-29 02:08:33 +0000", | ||
"allow_snapshots" : true, | ||
"allow_releases" : true | ||
} |
27 changes: 27 additions & 0 deletions
27
core-java/src/test/resources/repo-service/remote-central.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"type" : "remote", | ||
"key" : "maven:remote:central", | ||
"disabled" : false, | ||
"host" : "repo.maven.apache.org", | ||
"port" : 443, | ||
"name" : "central", | ||
"packageType" : "maven", | ||
"disable_timeout" : 0, | ||
"path_style" : "plain", | ||
"authoritative_index" : false, | ||
"create_time" : "2022-06-29 02:08:33 +0000", | ||
"allow_snapshots" : false, | ||
"allow_releases" : true, | ||
"url" : "https://repo.maven.apache.org/maven2/", | ||
"timeout_seconds" : 0, | ||
"max_connections" : 30, | ||
"ignore_hostname_verification" : false, | ||
"nfc_timeout_seconds" : 0, | ||
"is_passthrough" : false, | ||
"cache_timeout_seconds" : 86400, | ||
"metadata_timeout_seconds" : 0, | ||
"proxy_port" : 0, | ||
"prefetch_priority" : 0, | ||
"prefetch_rescan" : false, | ||
"prefetch_listing_type" : "html" | ||
} |