Skip to content

Commit

Permalink
cleanup java files
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity committed Dec 30, 2020
1 parent 531bb76 commit 0c720f0
Show file tree
Hide file tree
Showing 243 changed files with 3,014 additions and 3,021 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public void run() {
try {
throw new IllegalArgumentException();
} catch (Exception ex) {
System.out.println("exception test");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@

package com.azure.perf.test.core;

import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;

import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;

import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;

import reactor.core.publisher.Mono;

/**
Expand All @@ -35,7 +38,7 @@ public static HttpClient create(PerfStressOptions options) {

return httpClient;
}

private static void makeInsecure(HttpClient httpClient) {
Field nettyClientField;
try {
Expand Down Expand Up @@ -66,30 +69,29 @@ private static class ChangeUriHttpClient implements HttpClient {
private final HttpClient httpClient;
private final String host;
private final int port;

ChangeUriHttpClient(HttpClient httpClient, String host, int port) {
this.httpClient = httpClient;
this.host = host;
this.port = port;
}

@Override
public Mono<HttpResponse> send(HttpRequest request) {
request.getHeaders().put("Host", request.getUrl().getHost());

String protocol = request.getUrl().getProtocol();
String host = this.host;
int port = this.port;
String file = request.getUrl().getFile();

try {
request.setUrl(new URL(protocol, host, port, file));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}

return httpClient.send(request);
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

package com.azure.perf.test.core;

import com.beust.jcommander.JCommander;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.time.Duration;
Expand All @@ -17,6 +13,12 @@
import java.util.concurrent.ForkJoinPool;
import java.util.function.Supplier;
import java.util.stream.IntStream;

import com.beust.jcommander.JCommander;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

import reactor.core.Disposable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -77,6 +79,11 @@ public static void run(Class<?>[] classes, String[] args) {
}
}

private static String getCommandName(String testName) {
String lower = testName.toLowerCase();
return lower.endsWith("test") ? lower.substring(0, lower.length() - 4) : lower;
}

/**
* Run the performance test passed to be executed.
*
Expand Down Expand Up @@ -151,11 +158,6 @@ public static void run(Class<?> testClass, PerfStressOptions options) {
cleanupStatus.dispose();
}
}

private static String getCommandName(String testName) {
String lower = testName.toLowerCase();
return lower.endsWith("test") ? lower.substring(0, lower.length() - 4) : lower;
}

/**
* Runs the performance tests passed to be executed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
package com.azure.perf.test.core;

import com.azure.core.util.logging.ClientLogger;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.concurrent.atomic.AtomicInteger;
import reactor.core.publisher.Mono;


class SleepTest extends PerfStressTest<PerfStressOptions> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

package com.azure.perf.test.core;

import reactor.core.publisher.Flux;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.Random;
import reactor.core.publisher.Flux;

/**
* Utility class to help with data creation for perf testing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ public void visitToken(DetailAST ast) {
case TokenTypes.LITERAL_NEW:
checkLoggerInstantiation(ast);
break;
case TokenTypes.VARIABLE_DEF:
checkLoggerNameMatch(ast);
break;
case TokenTypes.METHOD_CALL:
final DetailAST dotToken = ast.findFirstToken(TokenTypes.DOT);
if (dotToken == null) {
Expand Down Expand Up @@ -162,26 +159,4 @@ private void checkLoggerInstantiation(DetailAST literalNewToken) {
return true;
});
}

/**
* Check if the given ClientLogger named 'logger'
*
* @param varToken VARIABLE_DEF node
*/
private void checkLoggerNameMatch(DetailAST varToken) {
if (!hasClientLoggerImported || !isTypeClientLogger(varToken)) {
return;
}
// Check if the Logger instance named as 'logger'.
final DetailAST identAST = varToken.findFirstToken(TokenTypes.IDENT);
if (identAST != null && !identAST.getText().equals(LOGGER)) {
log(varToken, String.format(LOGGER_NAME_ERROR, LOGGER, identAST.getText()));
}
// Check if the Logger is static instance, log as error if it is static instance logger.
if (TokenUtil.findFirstTokenByPredicate(varToken,
node -> node.getType() == TokenTypes.MODIFIERS
&& node.branchContains(TokenTypes.LITERAL_STATIC)).isPresent()) {
log(varToken, STATIC_LOGGER_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@
import com.puppycrawl.tools.checkstyle.checks.naming.AccessModifierOption;
import com.puppycrawl.tools.checkstyle.utils.CheckUtil;
import com.puppycrawl.tools.checkstyle.utils.TokenUtil;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
* Verify the classes with annotation @ServiceClient should have following rules:
Expand All @@ -29,8 +24,6 @@
*
* All methods that has a @ServiceMethod annotation in a class annotated with @ServiceClient should follow below rules:
* <ol>
* <li>Follows method naming pattern. Refer to
* <a href="https://azure.github.io/azure-sdk/java_introduction.html">Java Spec:</a></li>
* <li>Methods should not have "Async" added to the method name</li>
* <li>Return type of async and sync clients should be as per guidelines:
* <ol>
Expand Down Expand Up @@ -62,7 +55,6 @@ public class ServiceClientCheck extends AbstractCheck {
private static final String COLLECTION_RETURN_TYPE = "ReturnType.COLLECTION";
private static final String SINGLE_RETURN_TYPE = "ReturnType.SINGLE";

private static final String JAVA_SPEC_LINK = "https://azure.github.io/azure-sdk/java_introduction.html";
private static final String PAGED_FLUX = "PagedFlux";
private static final String MONO = "Mono";
private static final String RESPONSE = "Response";
Expand All @@ -80,10 +72,6 @@ public class ServiceClientCheck extends AbstractCheck {
private static final String SYNC_CONTEXT_ERROR =
"Synchronous method with annotation @ServiceMethod must has ''%s'' as a method parameter.";

private static final Set<String> COMMON_NAMING_PREFIX_SET = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
"upsert", "set", "create", "update", "replace", "delete", "add", "get", "list", "begin"
)));

// Add all imported classes into a map, key is the name of class and value is the full package path of class.
private final Map<String, String> simpleClassNameToQualifiedNameMap = new HashMap<>();

Expand Down Expand Up @@ -270,28 +258,20 @@ private void checkMethodNamingPattern(DetailAST methodDefToken) {
final DetailAST serviceMethodAnnotation = serviceMethodAnnotationOption.get();
final String methodName = methodDefToken.findFirstToken(TokenTypes.IDENT).getText();

// 1) Follows method naming pattern. Refer to Java Spec.
// prefix of method name that contains all lower letters
final String prefix = methodName.split("[A-Z]", 2)[0];
if (!methodName.endsWith("Exists") && !COMMON_NAMING_PREFIX_SET.contains(prefix)) {
log(methodDefToken, String.format(
"Method name ''%s'' should follow a common vocabulary. Refer to Java Spec: %s.",
methodName, JAVA_SPEC_LINK));
}

// 2) Methods should not have "Async" added to the method name
// 1) Methods should not have "Async" added to the method name
if (methodName.contains(ASYNC)) {
log(methodDefToken, String.format("Method name ''%s'' should not contain ''%s'' in the method name.",
methodName, ASYNC));
}

// 3) The return type of async and sync clients should be as per guidelines
// 2) The return type of async and sync clients should be as per guidelines
checkServiceClientMethodReturnType(methodDefToken, serviceMethodAnnotation, methodName);

// 4) Check 'withResponse' naming pattern
// 3) Check 'withResponse' naming pattern
checkReturnTypeNamingPattern(methodDefToken, methodName);

// 5) Synchronous method with annotation @ServiceMethod has to have {@code Context} as a parameter.
// 4) Synchronous method with annotation @ServiceMethod has to have {@code Context} as a parameter.
// Asynchronous method with annotation @ServiceMethod must not has {@code Context} as a parameter.
checkContextInRightPlace(methodDefToken);
}
Expand All @@ -306,7 +286,7 @@ private void checkMethodNamingPattern(DetailAST methodDefToken) {
* @param methodDefToken METHOD_DEF AST node
* @param serviceMethodAnnotation ANNOTATION AST node which used to find the if the annotation has 'return' key,
* @param methodName method name
* if found. return the value of member'return'.
* if found. return the value of member 'return'.
*/
private void checkServiceClientMethodReturnType(DetailAST methodDefToken, DetailAST serviceMethodAnnotation,
String methodName) {
Expand Down
Loading

0 comments on commit 0c720f0

Please sign in to comment.