Skip to content

Commit

Permalink
feat: enable checkstyle in sdk module (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
TedaLIEz authored Mar 2, 2023
1 parent 184ea80 commit 3c9a29f
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 50 deletions.
4 changes: 4 additions & 0 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ group = 'com.microsoft.hydralab'
version '2.2'
sourceCompatibility = 11
targetCompatibility = 11
apply from: "${project.rootDir}/quality/checkstyle.gradle"

classes.finalizedBy checkstyleMain

repositories {
mavenCentral()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.agent.runner;

/**
* We will gradually deprecate ThreadParam and AppiumParam, and migrate to this.
*
*/
public class TestRunThreadContext {
private static final InheritableThreadLocal<ITestRun> testRunThreadLocal = new InheritableThreadLocal<>();
public final class TestRunThreadContext {
private static final InheritableThreadLocal<ITestRun> TEST_RUN_INHERITABLE_THREAD_LOCAL = new InheritableThreadLocal<>();

private TestRunThreadContext() {

}

/**
* Should be called in the TestRunner setup lifecycle
*
* @param testRun
*/
static void init(ITestRun testRun) {
clean();
testRunThreadLocal.set(testRun);
TEST_RUN_INHERITABLE_THREAD_LOCAL.set(testRun);
}

public static void clean() {
testRunThreadLocal.remove();
TEST_RUN_INHERITABLE_THREAD_LOCAL.remove();
}

public static ITestRun getTestRun() {
return testRunThreadLocal.get();
return TEST_RUN_INHERITABLE_THREAD_LOCAL.get();
}
}
23 changes: 14 additions & 9 deletions sdk/src/main/java/com/microsoft/hydralab/appium/AppiumParam.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.appium;

public class AppiumParam {
Expand All @@ -13,6 +14,15 @@ public class AppiumParam {
public AppiumParam() {
}

public AppiumParam(String deviceId, String deviceName, String osVersion, int wdaPort, String apkPath, String outputDir) {
this.deviceId = deviceId;
this.deviceName = deviceName;
this.osVersion = osVersion;
this.wdaPort = wdaPort;
this.apkPath = apkPath;
this.outputDir = outputDir;
}

@Override
public String toString() {
return "AppiumParam{" +
Expand All @@ -25,27 +35,22 @@ public String toString() {
'}';
}

public AppiumParam(String deviceId, String deviceName, String osVersion, int wdaPort, String apkPath, String outputDir) {
this.deviceId = deviceId;
this.deviceName = deviceName;
this.osVersion = osVersion;
this.wdaPort = wdaPort;
this.apkPath = apkPath;
this.outputDir = outputDir;
}

public String getDeviceId() {
return deviceId;
}

public String getDeviceName() {
return deviceName;
}

public String getDeviceOsVersion() {
return osVersion;
}

public int getWdaPort() {
return wdaPort;
}

public String getApkPath() {
return apkPath;
}
Expand Down
27 changes: 15 additions & 12 deletions sdk/src/main/java/com/microsoft/hydralab/appium/ThreadParam.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.appium;

import java.util.Map;

/**
* TODO: rename this to TestRunThreadContext and move this above to package com.microsoft.hydralab
*/
public class ThreadParam {
private static final InheritableThreadLocal<AppiumParam> appiumParam = new InheritableThreadLocal<>();
private static final InheritableThreadLocal<Map<String, String>> configMap = new InheritableThreadLocal<>();
public final class ThreadParam {
private static final InheritableThreadLocal<AppiumParam> APPIUM_PARAM = new InheritableThreadLocal<>();
private static final InheritableThreadLocal<Map<String, String>> CONFIG_MAP = new InheritableThreadLocal<>();

private ThreadParam() {
}

public static void init(AppiumParam appiumParamTemp, Map<String, String> configMapParam) {
clean();
appiumParam.set(appiumParamTemp);
configMap.set(configMapParam);
APPIUM_PARAM.set(appiumParamTemp);
CONFIG_MAP.set(configMapParam);
}

public static void clean() {
appiumParam.remove();
configMap.remove();
APPIUM_PARAM.remove();
CONFIG_MAP.remove();
}

public static AppiumParam getAppiumParam() {
if (appiumParam == null) {
if (APPIUM_PARAM == null) {
return new AppiumParam();
}
AppiumParam temp = appiumParam.get();
AppiumParam temp = APPIUM_PARAM.get();
if (temp == null) {
return new AppiumParam();
}
return temp;
}


public static String getConfigString(String key) {
if (configMap == null) {
if (CONFIG_MAP == null) {
return null;
}
Map<String, String> temp = configMap.get();
Map<String, String> temp = CONFIG_MAP.get();
if (temp == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.performance;

public interface IPerformanceInspectionService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.performance;

import java.io.Serializable;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class InspectionStrategy implements Serializable {
@SuppressWarnings("visibilitymodifier")
public StrategyType strategyType;
@SuppressWarnings("visibilitymodifier")
public List<WhenType> when;
@SuppressWarnings("visibilitymodifier")
public long interval;
@SuppressWarnings("visibilitymodifier")
public TimeUnit intervalUnit;
@SuppressWarnings("visibilitymodifier")
public PerformanceInspection inspection;

enum StrategyType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.performance;

import java.io.File;
import java.io.Serializable;

import static com.microsoft.hydralab.performance.PerformanceInspector.PerformanceInspectorType.*;
import static com.microsoft.hydralab.performance.PerformanceInspector.PerformanceInspectorType.INSPECTOR_ANDROID_BATTERY_INFO;
import static com.microsoft.hydralab.performance.PerformanceInspector.PerformanceInspectorType.INSPECTOR_WIN_BATTERY;
import static com.microsoft.hydralab.performance.PerformanceInspector.PerformanceInspectorType.INSPECTOR_WIN_MEMORY;

public class PerformanceInspection implements Serializable {

@SuppressWarnings("visibilitymodifier")
public final PerformanceInspector.PerformanceInspectorType inspectorType;
@SuppressWarnings("visibilitymodifier")
public final String appId;
@SuppressWarnings("visibilitymodifier")
public final String deviceIdentifier;
@SuppressWarnings("visibilitymodifier")
public final String description;
@SuppressWarnings("visibilitymodifier")
public final String inspectionKey;
@SuppressWarnings("visibilitymodifier")
public final boolean isReset;
@SuppressWarnings("visibilitymodifier")
public File resultFolder;

public PerformanceInspection(String description, PerformanceInspector.PerformanceInspectorType inspectorType, String appId, String deviceIdentifier, boolean isReset) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.performance;

import java.io.File;

public class PerformanceInspectionResult {

@SuppressWarnings("visibilitymodifier")
public final long timestamp;
@SuppressWarnings("visibilitymodifier")
public PerformanceInspection inspection;

@SuppressWarnings("visibilitymodifier")
public File rawResultFile;
@SuppressWarnings("visibilitymodifier")
// TODO: restrict the size of it.
public Object parsedData;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.performance;

public enum PerformanceInspectionService implements IPerformanceInspectionService {
INSTANCE;

public static PerformanceInspectionService getInstance() {
return INSTANCE;
}

private IPerformanceInspectionService serviceImplementation = new IPerformanceInspectionService() {
@Override
public PerformanceInspectionResult inspect(PerformanceInspection performanceInspection) {
Expand All @@ -25,6 +22,10 @@ public PerformanceTestResult parse(PerformanceInspection performanceInspection)
}
};

public static PerformanceInspectionService getInstance() {
return INSTANCE;
}

void swapImplementation(IPerformanceInspectionService serviceImplementation) {
this.serviceImplementation = serviceImplementation;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.performance;

public interface PerformanceInspector {

PerformanceInspectionResult inspect(PerformanceInspection performanceInspection);

enum PerformanceInspectorType {
INSPECTOR_ANDROID_MEMORY_DUMP,
INSPECTOR_ANDROID_MEMORY_INFO,
Expand All @@ -12,6 +15,4 @@ enum PerformanceInspectorType {
INSPECTOR_WIN_BATTERY
}

PerformanceInspectionResult inspect(PerformanceInspection performanceInspection);

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.performance;

public interface PerformanceResultParser {
PerformanceTestResult parse(PerformanceTestResult performanceTestResult);

enum PerformanceResultParserType {
PARSER_ANDROID_MEMORY_DUMP,
PARSER_ANDROID_MEMORY_INFO,
PARSER_ANDROID_BATTERY_INFO,
PARSER_WIN_BATTERY,
PARSER_WIN_MEMORY
}

PerformanceTestResult parse(PerformanceTestResult performanceTestResult);
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.performance;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class PerformanceTestResult {
/**
* memory: java_heap_pss java_heap_rss native_heap_pss native_heap_rss code_pss code_rss stack_pss stack_rss
* graphics_pss graphics_rss private_other_pss private_other_rss system_pss system_rss unknown_pss unknown_rss
* total_pss total_rss total_swap_pss
* <p>
* battery: CPU screen Wake_lock other App_usage Total_usage
*/
private Object resultSummary;
/**
* TODO: Apply a max size to avoid OOM
*/
@SuppressWarnings("visibilitymodifier")
public List<PerformanceInspectionResult> performanceInspectionResults = new CopyOnWriteArrayList<>();
@SuppressWarnings("visibilitymodifier")
public PerformanceInspector.PerformanceInspectorType inspectorType;
@SuppressWarnings("visibilitymodifier")
public PerformanceResultParser.PerformanceResultParserType parserType;
/**
* memory: java_heap_pss java_heap_rss native_heap_pss native_heap_rss code_pss code_rss stack_pss stack_rss
* graphics_pss graphics_rss private_other_pss private_other_rss system_pss system_rss unknown_pss unknown_rss
* total_pss total_rss total_swap_pss
* <p>
* battery: CPU screen Wake_lock other App_usage Total_usage
*/
@SuppressWarnings("visibilitymodifier")
private Object resultSummary;

//TODO: overwrite equals, toString, and hashcode methods

public Object getResultSummary() {
return resultSummary;
}

public void setResultSummary(Object resultSummary) {
//TODO: restrict the usage
this.resultSummary = resultSummary;
}

public Object getResultSummary() {
return resultSummary;
}

@Override
public String toString() {
return "PerformanceTestResult{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ThreadParamTest {
@Test
public void init() {
logger.info("todo");
ThreadParam.init(null,null);
ThreadParam.init(null, null);
}

@Test
Expand Down

0 comments on commit 3c9a29f

Please sign in to comment.