Skip to content

Commit

Permalink
Polish handling of gRPC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ghillert committed Oct 28, 2022
1 parent c47b46e commit 37f2b9c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates.
* Copyright (c) 2013, 2022, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand All @@ -11,7 +11,7 @@
import com.oracle.coherence.spring.test.junit.CoherenceServerJunitExtension;
import com.tangosol.net.Coherence;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -27,7 +27,6 @@
* @author Gunnar Hillert
*
*/
@ExtendWith(CoherenceServerJunitExtension.class)
@SpringBootTest(classes = {
CoherenceConfigDataLoaderTests.DataLoaderConfig.class,
CoherenceConfigClientProperties.class
Expand All @@ -36,6 +35,10 @@
@DirtiesContext
public class CoherenceConfigDataLoaderTests {

@RegisterExtension
static CoherenceServerJunitExtension coherenceServerJunitExtension =
new CoherenceServerJunitExtension(true);

@Autowired
Environment env;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates.
* Copyright (c) 2013, 2022, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand All @@ -11,7 +11,7 @@
import com.tangosol.net.NamedCache;
import com.tangosol.net.Session;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -20,9 +20,12 @@
* @author Gunnar Hillert
*
*/
@ExtendWith(CoherenceServerJunitExtension.class)
public class CoherenceGrpcClientTests {

@RegisterExtension
static CoherenceServerJunitExtension coherenceServerJunitExtension =
new CoherenceServerJunitExtension(true);

final Coherence coherence;

public CoherenceGrpcClientTests(Coherence coherence) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates.
* Copyright (c) 2013, 2022, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand All @@ -19,7 +19,7 @@
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
Expand All @@ -33,11 +33,14 @@
* @author Gunnar Hillert
*/
@SpringJUnitConfig(GrpcSessionBeanTests.Config.class)
@ExtendWith(CoherenceServerJunitExtension.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@DirtiesContext
public class GrpcSessionBeanTests {

@RegisterExtension
static CoherenceServerJunitExtension coherenceServerJunitExtension =
new CoherenceServerJunitExtension(true);

final Coherence coherence;

public GrpcSessionBeanTests(Coherence coherence) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,22 @@ public class CoherenceServerJunitExtension implements ParameterResolver,
protected static final Log logger = LogFactory.getLog(CoherenceServerJunitExtension.class);

private final String configUri;
private final boolean grpcEnabled;

private Coherence coherence;

public CoherenceServerJunitExtension() {
public CoherenceServerJunitExtension(boolean grpcEnabled) {
this.configUri = "coherence-cache-config.xml";
this.grpcEnabled = grpcEnabled;
}

public CoherenceServerJunitExtension() {
this(false);
}

public CoherenceServerJunitExtension(String configUri) {
this.configUri = configUri;
this.grpcEnabled = false;
}

@Override
Expand All @@ -51,6 +58,7 @@ public void afterAll(ExtensionContext context) {
this.coherence.whenClosed().join();

System.clearProperty("coherence.log");
System.clearProperty("coherence.grpc.enabled");
System.clearProperty("coherence.grpc.server.port");

if (logger.isInfoEnabled()) {
Expand All @@ -61,6 +69,7 @@ public void afterAll(ExtensionContext context) {
@Override
public void beforeAll(ExtensionContext context) throws Exception {
System.setProperty("coherence.log", "slf4j");
System.setProperty("coherence.grpc.enabled", String.valueOf(this.grpcEnabled));
System.setProperty("coherence.grpc.server.port", "1408");

if (logger.isInfoEnabled()) {
Expand Down

0 comments on commit 37f2b9c

Please sign in to comment.