Skip to content

Commit 8d5aa2d

Browse files
docs:adding Java docs to the code base (keploy#143)
* Adding Java docs Signed-off-by: charankamarapu <[email protected]> * Adding Java docs Signed-off-by: charankamarapu <[email protected]> --------- Signed-off-by: charankamarapu <[email protected]>
1 parent c3a29af commit 8d5aa2d

39 files changed

+521
-182
lines changed

agent/src/main/java/io/keploy/advice/CustomGoogleResponseAdvice.java

+8
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@
1313
import java.lang.reflect.Method;
1414
import java.util.Objects;
1515

16+
/**
17+
* This class is used for intercepting method parseResponse of OkHttpPendingResult class and to record required data from
18+
* the method
19+
*/
1620
public class CustomGoogleResponseAdvice {
1721

22+
/**
23+
* This method gets executed before method parseResponse of OkHttpPendingResult class. In record mode it saves the
24+
* data from the parseResponse method arguments and help in recording mocks/tests.
25+
*/
1826
@Advice.OnMethodEnter
1927
static void enterMethods(@Advice.Origin Method method, @Advice.AllArguments Object[] obj) throws Exception {
2028
final Logger logger = LogManager.getLogger(CustomGoogleResponseAdvice.class);

agent/src/main/java/io/keploy/advice/OkHttpAdvice_Kotlin.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@
99
import java.lang.reflect.Constructor;
1010

1111

12+
/**
13+
* This class is used for intercepting constructor of OkHttpClient$Builder class and to add an interceptor to its builder
14+
*/
1215
public class OkHttpAdvice_Kotlin {
1316

14-
17+
/**
18+
* This method gets executed before the constructor of OkHttpClient$Builder class.This does nothing as we don't
19+
* want to change anything before the invocation of OkHttpClient$Builder constructor.
20+
*/
1521
@Advice.OnMethodEnter
1622
static void enterMethods(@Advice.Origin Constructor constructor) throws Exception {
1723
}
1824

25+
/**
26+
* This method gets executed after constructor of OkHttpClient$Builder class and Adds a interceptor to its builder
27+
*
28+
* @param builder - OkHttpClient.Builder
29+
*/
1930
@Advice.OnMethodExit
2031
static void exitMethods(@Advice.Origin Constructor constructor, @Advice.This OkHttpClient.Builder builder) {
2132
final Logger logger = LogManager.getLogger(OkHttpAdvice_Kotlin.class);

agent/src/main/java/io/keploy/advice/ksql/DataBaseMetaData_Advice.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.keploy.advice.ksql;
22

3-
43
import io.keploy.ksql.KDatabaseMetaData;
54
import net.bytebuddy.asm.Advice;
65
import org.apache.logging.log4j.LogManager;
@@ -9,12 +8,27 @@
98
import java.lang.reflect.Constructor;
109
import java.sql.DatabaseMetaData;
1110

11+
12+
/**
13+
* This class is used for intercepting constructor of NewProxyDatabaseMetaData class and to replace value of a field to
14+
* a custom value i.e. KDatabaseMetaData on exit of that constructor method.
15+
*/
1216
public class DataBaseMetaData_Advice {
1317

18+
/**
19+
* This method gets executed before the constructor of NewProxyDatabaseMetaData class.This does nothing as we don't
20+
* want to change anything before the invocation of NewProxyDatabaseMetaData constructor.
21+
*/
1422
@Advice.OnMethodEnter
1523
static void enterMethods(@Advice.Origin Constructor constructor) throws Exception {
1624
}
1725

26+
/**
27+
* This method gets executed after constructor of NewProxyDatabaseMetaData class and replaces the value of field metaData
28+
* to KDatabaseMetaData .
29+
*
30+
* @param metaData - a field in NewProxyDatabaseMetaData class
31+
*/
1832
@Advice.OnMethodExit
1933
static void exitMethods(@Advice.Origin Constructor constructor, @Advice.FieldValue(value = "inner", readOnly = false) DatabaseMetaData metaData) {
2034
final Logger logger = LogManager.getLogger(DataBaseMetaData_Advice.class);

agent/src/main/java/io/keploy/advice/ksql/HealthCheckInterceptor.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,30 @@
44

55
import java.lang.reflect.Method;
66

7+
/**
8+
* This class is used for intercepting method withDetail of Health$Builder class and to replace an argument value to
9+
* a custom value on entry of that withDetail method.
10+
*/
711
public class HealthCheckInterceptor {
812

13+
/**
14+
* This method gets executed before the withDetail method of Health$Builder class.In test mode of keploy this method
15+
* will throw error as we don't get health check from database. so we mock the health check response and feed it to
16+
* the method. Whenever the value of the health check argument is NULL we replace it with "HI" so that the method
17+
* never fails
18+
*/
919
@Advice.OnMethodEnter
1020
public static void enterMethod(@Advice.Origin Method method, @Advice.Argument(value = 0, readOnly = false) String key, @Advice.Argument(value = 1, readOnly = false) Object value) {
11-
// System.out.println("Inside Enter Advice: " + method);
12-
// System.out.println("Health Checkk !!");
1321
if (value == null) {
1422
value = "HI";
1523
}
1624
}
1725

26+
/**
27+
* This method gets executed after the withDetail method of Health$Builder class.This does nothing as we don't
28+
* want to change anything after the completion of withDetail method of Health$Builder class.
29+
*/
1830
@Advice.OnMethodExit
1931
public static void exitMethod(@Advice.Origin Method method) {
20-
// System.out.println("Inside Exit Advice: " + method);
2132
}
2233
}

agent/src/main/java/io/keploy/advice/ksql/RegisterDialect.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,27 @@
77
import java.lang.reflect.Constructor;
88
import java.util.Map;
99

10+
/**
11+
* This class is used for intercepting constructor of JpaProperties class and to modify the value of a field value of
12+
* the class on exit of that constructor method.
13+
*/
1014
public class RegisterDialect {
1115

16+
/**
17+
* This method gets executed before the constructor of JpaProperties class.This does nothing as we don't
18+
* want to change anything before the invocation of JpaProperties constructor.
19+
*/
1220
@Advice.OnMethodEnter
1321
static void enterMethods(@Advice.Origin Constructor constructor) throws Exception {
14-
// System.out.println("Inside RegisterDialect Enter Advice: " + constructor);
1522
}
1623

24+
/**
25+
* This method gets executed after constructor of JpaProperties class and modifies the value of the field - properties.
26+
*
27+
* @param properties - a field in JpaProperties class
28+
*/
1729
@Advice.OnMethodExit
1830
static void exitMethods(@Advice.Origin Constructor constructor, @Advice.FieldValue(readOnly = false, value = "properties") Map<String, String> properties) throws Exception {
19-
// System.out.println("Inside RegisterDialect Exit Advice: " + constructor);
2031
properties.put("hibernate.dialect", KDriver.Dialect);
2132
}
2233
}

agent/src/main/java/io/keploy/advice/ksql/RegisterDriverAdvice.java

+13-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55

66
import java.lang.reflect.Method;
77

8-
//@Component
8+
/**
9+
* This class is used for intercepting method setDriverClassName of DataSourceProperties class and to replace an argument value to
10+
* a custom value on entry of setDriverClassName method.
11+
*/
912
public class RegisterDriverAdvice {
1013

14+
/**
15+
* This method gets executed before the setDriverClassName method of DataSourceProperties class. According to the
16+
* driverClassName that is present, Dialect of KDriver is changed and driverClassName value is replaced with KDriver
17+
* path
18+
*/
1119
@Advice.OnMethodEnter
1220
public static void enterMethod(@Advice.Origin Method method, @Advice.Argument(value = 0, readOnly = false) String driverClassName) {
13-
// System.out.println("Entering method[" + method + "] with argument[" + driverClassName + "] from EnterAdvice");
1421

1522
if (driverClassName != null && !driverClassName.equals("io.keploy.ksql.KDriver")) {
1623
KDriver.DriverName = driverClassName;
@@ -32,16 +39,14 @@ public static void enterMethod(@Advice.Origin Method method, @Advice.Argument(va
3239
System.out.println("Dialect for driver: " + driverClassName + " is not supported yet");
3340
}
3441
}
35-
// mode.ModeType KEPLOY_MODE = mode.getMode();
36-
// System.out.println(KEPLOY_MODE);
37-
// if (KEPLOY_MODE.equals(mode.ModeType.MODE_OFF)){
38-
// return;
39-
// }
4042
driverClassName = "io.keploy.ksql.KDriver";
4143
}
4244

45+
/**
46+
* This method gets executed after the setDriverClassName method of DataSourceProperties class.This does nothing as we don't
47+
* want to change anything after the completion of the setDriverClassName method of DataSourceProperties class.
48+
*/
4349
@Advice.OnMethodExit
4450
public static void exitMethod(@Advice.Origin Method method) {
45-
// System.out.println("exit advice -> " + method);
4651
}
4752
}

agent/src/main/java/io/keploy/advice/ksql/RegisterDriverAdvice_Interceptor.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,24 @@
88
import java.util.concurrent.Callable;
99

1010

11+
/**
12+
* This class is used for intercepting method determineDriverClassName of DataSourceProperties class and returns a
13+
* custom value instead of value returned by the determineDriverClassName method .
14+
*/
1115
public class RegisterDriverAdvice_Interceptor {
1216

17+
/**
18+
* This method will get called instead of determineDriverClassName
19+
* @param client - original method client
20+
* @param method - contains all the details regarding original method
21+
* @return - path to Driver class
22+
*/
1323
public static String execute(@SuperCall Callable<String> client, @Origin Method method) throws Exception {
14-
// System.out.println("Inside RegisterDriverAdvice_Interceptor -> " + method);
24+
25+
// Getting actual response from original method
1526
String s = client.call();
16-
// System.out.println("determineDriverClassName returns : " + s);
27+
28+
// Changing KDriver Dialect according to the response from original method
1729
if (s != null && !s.equals("io.keploy.ksql.KDriver")) {
1830
KDriver.DriverName = s;
1931
switch (s) {
@@ -34,6 +46,8 @@ public static String execute(@SuperCall Callable<String> client, @Origin Method
3446
System.out.println("Dialect for driver: " + s + " is not supported yet");
3547
}
3648
}
49+
50+
// returning wrapped Driver class path
3751
return "io.keploy.ksql.KDriver";
3852
}
3953
}

agent/src/main/java/io/keploy/advice/ksql/SetDdlAuto_Advice.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,26 @@
44

55
import java.lang.reflect.Method;
66

7+
/**
8+
* This class is used for intercepting method setDdlAuto of HibernateProperties class and to replace an argument value to
9+
* a custom value on entry of setDdlAuto method.
10+
*/
711
public class SetDdlAuto_Advice {
812

13+
/**
14+
* This method gets executed before the setDdlAuto method of HibernateProperties class. According to the
15+
* Keploy mode that is present, The argument value will be changed.
16+
*/
917
@Advice.OnMethodEnter
1018
public static void enterMethod(@Advice.Origin Method method, @Advice.Argument(value = 0, readOnly = false) String ddlAuto) {
11-
// System.out.println("Entering method[" + method + "] with argument[" + ddlAuto + "] from EnterAdvice");
1219
ddlAuto = (System.getenv("KEPLOY_MODE").equals("test")) ? "none" : ddlAuto;
1320
}
1421

22+
/**
23+
* This method gets executed after the setDdlAuto method of HibernateProperties class.This does nothing as we don't
24+
* want to change anything after the completion of the setDdlAuto method of HibernateProperties class.
25+
*/
1526
@Advice.OnMethodExit
1627
public static void exitMethod(@Advice.Origin Method method) {
17-
// System.out.println("exit advice -> " + method);
1828
}
1929
}

agent/src/main/java/io/keploy/advice/ksql/SetEnabled_Advice.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,26 @@
44

55
import java.lang.reflect.Method;
66

7+
/**
8+
* This class is used for intercepting method setEnabled of LiquibaseProperties class and to replace an argument value to
9+
* a custom value on entry of setEnabled method.
10+
*/
711
public class SetEnabled_Advice {
812

13+
/**
14+
* This method gets executed before the setEnabled method of LiquibaseProperties class. According to the
15+
* Keploy mode that is present, The argument value will be changed
16+
*/
917
@Advice.OnMethodEnter
1018
public static void enterMethod(@Advice.Origin Method method, @Advice.Argument(value = 0, readOnly = false) boolean enabled) {
11-
// System.out.println("Entering method[" + method + "] with argument[" + enabled + "] from EnterAdvice");
1219
enabled = (System.getenv("KEPLOY_MODE").equals("test")) ? false : enabled;
1320
}
1421

22+
/**
23+
* This method gets executed after the setEnabled method of LiquibaseProperties class.This does nothing as we don't
24+
* want to change anything after the completion of the setEnabled method of LiquibaseProperties class.
25+
*/
1526
@Advice.OnMethodExit
1627
public static void exitMethod(@Advice.Origin Method method) {
17-
// System.out.println("exit advice -> " + method);
1828
}
1929
}

0 commit comments

Comments
 (0)