Skip to content

Commit

Permalink
GEODE-6822: removed test duplication (apache#3725)
Browse files Browse the repository at this point in the history
* tests were having difficulty with existing rules and been fixed by moving to their own class
  * removing tests that should have originally been removed
  • Loading branch information
jhuynh1 authored and nabarunnag committed Jun 18, 2019
1 parent a60ade2 commit 628b8dd
Showing 1 changed file with 0 additions and 331 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,337 +142,6 @@ public void deployNewVersionOfFunctionOverOldVersion() throws Exception {
assertThat(result.get(0)).isEqualTo("Version2");
}

@Test
public void deployingJarsUnrelatedToDeserializedObjectsShouldNotCauseFailingInstanceOfChecks()
throws Exception {
String classAName = "classA";
String classBName = "classB";

File jarA = createVersionOfJar("JarAVersion11", classAName, "JarA.jar");
File jarB = createVersionOfJar("JarBVersion11", classBName, "JarB.jar");

ClassPathLoader.getLatest().getJarDeployer().deploy("JarA.jar", jarA);
Class class1 =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classAName);
Object classAInstance = class1.newInstance();

ClassPathLoader.getLatest().getJarDeployer().deploy("JarB.jar", jarB);
Class class2 =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classAName);
Object anotherClassAInstance = class2.newInstance();

assertThat(classAInstance).isInstanceOf(anotherClassAInstance.getClass());
}

@Test
public void shouldBeAbleToLoadClassesWithInterdependenciesAcrossDifferentJars() throws Exception {
String classAName = "classA";
String classBName = "classB";

String classAContents =
"package jddunit.function;"
+ "public class "
+ classAName + " extends " + classBName
+ " { public boolean hasResult() {return true;}}";
String classBContents =
"package jddunit.function;"
+ "public class "
+ classBName + " { public boolean someMethod() {return true;}}";

File jarB = createJarFromClassContents("JarBVersion1", classBName, "JarB.jar", classBContents);
File jarA = createJarFromClassContents("JarAVersion1", classAName, "JarA.jar", classAContents,
jarB.getAbsolutePath());

ClassPathLoader.getLatest().getJarDeployer().deploy("JarA.jar", jarA);
ClassPathLoader.getLatest().getJarDeployer().deploy("JarB.jar", jarB);

Class classA =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classAName);
Object classAInstance = classA.newInstance();

assertThat(classAName).isEqualTo(classAInstance.getClass().getSimpleName());
}

@Test
public void loadingInterdependentJarsShouldNotCauseClassIncompatibilities() throws Exception {
String classAName = "classA";
String classBName = "classB";

String classAContents =
"package jddunit.function;"
+ "public class "
+ classAName + " extends " + classBName
+ " { public boolean hasResult() {return true;}}";

String classBContents =
"package jddunit.function;"
+ "public class "
+ classBName + " { public boolean someMethod() {return true;}}";

File jarB = createJarFromClassContents("JarBVersion1", classBName, "JarB.jar", classBContents);
File jarA = createJarFromClassContents("JarAVersion1", classAName, "JarA.jar", classAContents,
jarB.getAbsolutePath());

ClassPathLoader.getLatest().getJarDeployer().deploy("JarA.jar", jarA);
ClassPathLoader.getLatest().getJarDeployer().deploy("JarB.jar", jarB);

Class classA =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classAName);
Object classAInstance = classA.newInstance();

Class classB =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classBName);
Object classBInstance = classB.newInstance();

assertThat(classBInstance.getClass()).isAssignableFrom(classAInstance.getClass());
}

@Test
public void loadingParentClassFirstFromInterdependentJarsShouldNotCauseClassIncompatibilities()
throws Exception {
String classAName = "classA";
String classBName = "classB";

String classAContents =
"package jddunit.function;"
+ "public class "
+ classAName + " extends " + classBName
+ " { public boolean hasResult() {return true;}}";

String classBContents =
"package jddunit.function;"
+ "public class "
+ classBName + " { public boolean someMethod() {return true;}}";

File jarB = createJarFromClassContents("JarBVersion1", classBName, "JarB.jar", classBContents);
File jarA = createJarFromClassContents("JarAVersion1", classAName, "JarA.jar", classAContents,
jarB.getAbsolutePath());

ClassPathLoader.getLatest().getJarDeployer().deploy("JarB.jar", jarB);
Class classB =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classBName);
Object classBInstance = classB.newInstance();

ClassPathLoader.getLatest().getJarDeployer().deploy("JarA.jar", jarA);
Class classA =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classAName);
Object classAInstance = classA.newInstance();

Class classB2 =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classBName);
Object classB2Instance = classB2.newInstance();

assertThat(classB2Instance).isInstanceOf(classBInstance.getClass());
assertThat(classBInstance.getClass()).isAssignableFrom(classAInstance.getClass());
}

@Test
public void redeployingParentClassDoesNotCauseSubclassIncompatibilities() throws Exception {
String classAName = "classA";
String classBName = "classB";

String classAContents =
"package jddunit.function;"
+ "public class "
+ classAName + " extends " + classBName
+ " { public boolean hasResult() {return true;}}";

String classBContents =
"package jddunit.function;"
+ "public class "
+ classBName + " { public boolean someMethod() {return true;}}";

String classB2Contents =
"package jddunit.function;"
+ "public class "
+ classBName + " { public boolean someMethod() {return false;}}";

File jarB = createJarFromClassContents("JarBVersion1", classBName, "JarB.jar", classBContents);
File jarA = createJarFromClassContents("JarAVersion1", classAName, "JarA.jar", classAContents,
jarB.getAbsolutePath());
File jarBV2 =
createJarFromClassContents("JarBVersion2", classBName, "JarB.jar", classB2Contents);

ClassPathLoader.getLatest().getJarDeployer().deploy("JarB.jar", jarB);
Class classB =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classBName);
Object classBInstance = classB.newInstance();

ClassPathLoader.getLatest().getJarDeployer().deploy("JarA.jar", jarA);
Class classA =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classAName);
Object classAInstance = classA.newInstance();

ClassPathLoader.getLatest().getJarDeployer().deploy("JarB.jar", jarBV2);

Class classA2 =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classAName);
Object classA2Instance = classA2.newInstance();

assertThat(classA2Instance).isInstanceOf(classAInstance.getClass());
}

@Test
public void redeployingParentClassIfParentDeployedLastDoesNotCauseSubclassIncompatibilities()
throws Exception {
String classAName = "classA";
String classBName = "classB";

String classAContents =
"package jddunit.function;"
+ "public class "
+ classAName + " extends " + classBName
+ " { public boolean hasResult() {return true;}}";

String classBContents =
"package jddunit.function;"
+ "public class "
+ classBName + " { public boolean someMethod() {return true;}}";

String classB2Contents =
"package jddunit.function;"
+ "public class "
+ classBName + " { public boolean someMethod() {return false;}}";

File jarB = createJarFromClassContents("JarBVersion1", classBName, "JarB.jar", classBContents);
File jarA = createJarFromClassContents("JarAVersion1", classAName, "JarA.jar", classAContents,
jarB.getAbsolutePath());
File jarBV2 =
createJarFromClassContents("JarBVersion2", classBName, "JarB.jar", classB2Contents);

ClassPathLoader.getLatest().getJarDeployer().deploy("JarA.jar", jarA);
ClassPathLoader.getLatest().getJarDeployer().deploy("JarB.jar", jarB);

Class classA =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classAName);
Object classAInstance = classA.newInstance();

Class classB =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classBName);
Object classBInstance = classB.newInstance();

ClassPathLoader.getLatest().getJarDeployer().deploy("JarB.jar", jarBV2);
Class classA2 =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classAName);
Object classA2Instance = classA2.newInstance();

assertThat(classA2Instance).isInstanceOf(classAInstance.getClass());
}


@Test(expected = ClassNotFoundException.class)
public void redeployingJarWithRemovedClassShouldNoLongerAllowLoadingRemovedClass()
throws Exception {
String classAName = "classA";
String classBName = "classB";
String classB2Name = "classB2";

String classAContents =
"package jddunit.function;"
+ "public class "
+ classAName + " extends " + classBName
+ " { public boolean hasResult() {return true;}}";

String classBContents =
"package jddunit.function;"
+ "public class "
+ classBName + " { public boolean someMethod() {return true;}}";

String classB2Contents =
"package jddunit.function;"
+ "public class "
+ classB2Name + " { public boolean someMethod() {return false;}}";

File jarB = createJarFromClassContents("JarBVersion1", classBName, "JarB.jar", classBContents);
File jarA = createJarFromClassContents("JarAVersion1", classAName, "JarA.jar", classAContents,
jarB.getAbsolutePath());
File jarBV2 =
createJarFromClassContents("JarBVersion2", classB2Name, "JarB.jar", classB2Contents);

ClassPathLoader.getLatest().getJarDeployer().deploy("JarB.jar", jarB);
Class classB =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classBName);
Object classBInstance = classB.newInstance();

ClassPathLoader.getLatest().getJarDeployer().deploy("JarB.jar", jarBV2);
Class classB2 =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classBName);
}

@Test
public void undeployedUnrelatedJarShouldNotAffectDeserializedObjectComparison() throws Exception {
String classAName = "classA";
String classBName = "classB";

String classAContents =
"package jddunit.function;"
+ "public class "
+ classAName + " { public boolean hasResult() {return true;}}";

String classBContents =
"package jddunit.function;"
+ "public class "
+ classBName + " { public boolean someMethod() {return true;}}";

File jarB = createJarFromClassContents("JarBVersion1", classBName, "JarB.jar", classBContents);
File jarA = createJarFromClassContents("JarAVersion1", classAName, "JarA.jar", classAContents);

ClassPathLoader.getLatest().getJarDeployer().deploy("JarB.jar", jarB);
Class classB =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classBName);
Object classBInstance = classB.newInstance();

ClassPathLoader.getLatest().getJarDeployer().deploy("JarA.jar", jarA);
Class classA =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classAName);
Object classAInstance = classA.newInstance();

ClassPathLoader.getLatest().getJarDeployer().undeploy("JarB.jar");
Object classA2Instance = classA.newInstance();
assertThat(classA2Instance).isInstanceOf(classAInstance.getClass());
}

@Test(expected = ClassNotFoundException.class)
public void undeployedJarShouldNoLongerAllowLoadingUndeployedClass() throws Exception {
String classAName = "classA";
String classBName = "classB";
String classB2Name = "classB2";

String classAContents =
"package jddunit.function;"
+ "public class "
+ classAName + " { public boolean hasResult() {return true;}}";

String classBContents =
"package jddunit.function;"
+ "public class "
+ classBName + " { public boolean someMethod() {return true;}}";

String classB2Contents =
"package jddunit.function;"
+ "public class "
+ classB2Name + " { public boolean someMethod() {return false;}}";

File jarB = createJarFromClassContents("JarBVersion1", classBName, "JarB.jar", classBContents);
File jarA = createJarFromClassContents("JarAVersion1", classAName, "JarA.jar", classAContents,
jarB.getAbsolutePath());

ClassPathLoader.getLatest().getJarDeployer().deploy("JarB.jar", jarB);
Class classB =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classBName);
Object classBInstance = classB.newInstance();

Class classA =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classAName);
Object classAInstance = classA.newInstance();

ClassPathLoader.getLatest().getJarDeployer().undeploy("JarB.jar");
classB =
ClassPathLoader.getLatest().asClassLoader().loadClass("jddunit.function." + classBName);
classBInstance = classB.newInstance();

}

private File createVersionOfJar(String version, String functionName, String jarName)
throws IOException {
String classContents =
Expand Down

0 comments on commit 628b8dd

Please sign in to comment.