Skip to content

Commit

Permalink
GEODE-6883: Introduce ArchUnit test for membership (apache#3748)
Browse files Browse the repository at this point in the history
Using ArchUnit to write a test that membership classes must only
depend on other membership classes.

Co-Authored-By: Bill Burcham <[email protected]>
Co-Authored-By: Ernest Burghardt <[email protected]>
Co-Authored-By: Dan Smith <[email protected]>
  • Loading branch information
3 people authored and kirklund committed Jun 27, 2019
1 parent c243ac0 commit 29d28b9
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 26 deletions.
6 changes: 6 additions & 0 deletions boms/geode-all-bom/src/test/resources/expected-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
<version>2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit4</artifactId>
<version>0.10.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class DependencyConstraints implements Plugin<Project> {
api(group: 'com.mockrunner', name: 'mockrunner-servlet', version: '1.1.2')
api(group: 'com.sun.activation', name: 'javax.activation', version: '1.2.0')
api(group: 'com.sun.istack', name: 'istack-commons-runtime', version: '2.2')
api(group: 'com.tngtech.archunit', name:'archunit-junit4', version: '0.10.2')
api(group: 'com.zaxxer', name: 'HikariCP', version: '3.2.0')
api(group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.3')
api(group: 'commons-collections', name: 'commons-collections', version: '3.2.2')
Expand Down
1 change: 1 addition & 0 deletions geode-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ dependencies {
testCompile('org.powermock:powermock-module-junit4')
testCompile('org.powermock:powermock-api-mockito2')
testCompile('pl.pragmatists:JUnitParams')
testImplementation('com.tngtech.archunit:archunit-junit4')

testCompile files("${System.getProperty('java.home')}/../lib/tools.jar")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ private Pair<MembershipManager, DistributedMembershipListener> createMembershipM
final DistributedMembershipListener listener = mock(DistributedMembershipListener.class);
final DMStats stats1 = mock(DMStats.class);
final InternalDistributedSystem mockSystem = mock(InternalDistributedSystem.class);
when(mockSystem.getConfig()).thenReturn(config);
System.out.println("creating 1st membership manager");
final SecurityService securityService = SecurityServiceFactory.create();
final MembershipManager m1 =
MemberFactory.newMembershipManager(listener, mockSystem, transport, stats1,
securityService, new GMSAuthenticator(config.getSecurityProps(), securityService,
mockSystem.getSecurityLogWriter(), mockSystem.getInternalLogWriter()));
MemberFactory.newMembershipManager(listener, transport, stats1,
new GMSAuthenticator(config.getSecurityProps(), securityService,
mockSystem.getSecurityLogWriter(), mockSystem.getInternalLogWriter()),
config);
m1.startEventProcessing();
return Pair.of(m1, listener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.apache.geode.internal.Version;
import org.apache.geode.internal.admin.remote.RemoteTransportConfig;
import org.apache.geode.internal.net.SocketCreator;
import org.apache.geode.internal.security.SecurityServiceFactory;
import org.apache.geode.test.junit.categories.MembershipTest;

@Category(MembershipTest.class)
Expand Down Expand Up @@ -162,10 +161,11 @@ public void testRecoverFromOther() throws Exception {
when(mockSystem.getConfig()).thenReturn(config);

// start the membership manager
membershipManager = MemberFactory.newMembershipManager(mockListener, mockSystem, transport,
mockDmStats, SecurityServiceFactory.create(),
membershipManager = MemberFactory.newMembershipManager(mockListener, transport,
mockDmStats,
new GMSAuthenticator(mockSystem.getSecurityProperties(), mockSystem.getSecurityService(),
mockSystem.getSecurityLogWriter(), mockSystem.getInternalLogWriter()));
mockSystem.getSecurityLogWriter(), mockSystem.getInternalLogWriter()),
mockSystem.getConfig());

GMSLocator gmsLocator = new GMSLocator(localHost,
membershipManager.getLocalMember().getHost() + "[" + port + "]", true, true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,10 +780,11 @@ private ClusterDistributionManager(RemoteTransportConfig transport,
long start = System.currentTimeMillis();

DMListener l = new DMListener(this);
membershipManager = MemberFactory.newMembershipManager(l, system, transport,
stats, system.getSecurityService(),
membershipManager = MemberFactory.newMembershipManager(l, transport,
stats,
new GMSAuthenticator(system.getSecurityProperties(), system.getSecurityService(),
system.getSecurityLogWriter(), system.getInternalLogWriter()));
system.getSecurityLogWriter(), system.getInternalLogWriter()),
system.getConfig());

sb.append(System.currentTimeMillis() - start);

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

import org.apache.geode.annotations.Immutable;
import org.apache.geode.distributed.internal.DMStats;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.distributed.internal.LocatorStats;
import org.apache.geode.distributed.internal.membership.gms.GMSMemberFactory;
import org.apache.geode.distributed.internal.membership.gms.NetLocator;
import org.apache.geode.distributed.internal.membership.gms.interfaces.Authenticator;
import org.apache.geode.internal.admin.remote.RemoteTransportConfig;
import org.apache.geode.internal.security.SecurityService;

/**
* Create a new Member based on the given inputs. TODO: need to implement a real factory
Expand Down Expand Up @@ -87,14 +86,14 @@ public static NetMember newNetMember(String s, int p) {
* @param stats are used for recording statistical communications information
* @return a MembershipManager
*/
public static MembershipManager newMembershipManager(DistributedMembershipListener listener,
InternalDistributedSystem system,
RemoteTransportConfig transport,
DMStats stats,
SecurityService securityService,
final Authenticator authenticator) {
return services.newMembershipManager(listener, transport, stats,
authenticator, system.getConfig());
public static MembershipManager newMembershipManager(
final DistributedMembershipListener listener,
final RemoteTransportConfig transport,
final DMStats stats,
final Authenticator authenticator,
final DistributionConfig config) {
return services.newMembershipManager(listener, transport, stats, authenticator,
config);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ NetMember newNetMember(InetAddress i, int port, boolean splitBrainEnabled,
MembershipManager newMembershipManager(DistributedMembershipListener listener,
RemoteTransportConfig transport,
DMStats stats,
final Authenticator authenticator,
Authenticator authenticator,
DistributionConfig config);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ public NetMember newNetMember(String s, int p) {
}

@Override
public MembershipManager newMembershipManager(DistributedMembershipListener listener,
RemoteTransportConfig transport, DMStats stats,
public MembershipManager newMembershipManager(
final DistributedMembershipListener listener,
final RemoteTransportConfig transport, DMStats stats,
final Authenticator authenticator,
DistributionConfig config) throws DistributionException {
final DistributionConfig config) throws DistributionException {
Services services = new Services(listener, transport, stats, authenticator, config);
try {
services.init();
Expand Down
Loading

0 comments on commit 29d28b9

Please sign in to comment.