Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: get ./gradlew format to pass for the whole repo #29766

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public StateApi getStateApi() {
* an 10-minute wait for the last retry.
*/
public static <T> T retryWithJitter(final Callable<T> call, final String desc) {
return retryWithJitter(call, desc, DEFAULT_RETRY_INTERVAL_SECS, DEFAULT_FINAL_INTERVAL_SECS, DEFAULT_MAX_RETRIES);
return retryWithJitter(
call, desc, DEFAULT_RETRY_INTERVAL_SECS, DEFAULT_FINAL_INTERVAL_SECS, DEFAULT_MAX_RETRIES);
}

/**
Expand All @@ -158,11 +159,12 @@ public static <T> T retryWithJitter(final Callable<T> call, final String desc) {
@VisibleForTesting
// This is okay since we are logging the stack trace, which PMD is not detecting.
@SuppressWarnings("PMD.PreserveStackTrace")
public static <T> T retryWithJitter(final Callable<T> call,
final String desc,
final int jitterMaxIntervalSecs,
final int finalIntervalSecs,
final int maxTries) {
public static <T> T retryWithJitter(
final Callable<T> call,
final String desc,
final int jitterMaxIntervalSecs,
final int finalIntervalSecs,
final int maxTries) {
int currRetries = 0;
boolean keepTrying = true;

Expand Down Expand Up @@ -195,5 +197,4 @@ public static <T> T retryWithJitter(final Callable<T> call,
}
return data;
}

}
29 changes: 16 additions & 13 deletions airbyte-api/src/main/java/io/airbyte/api/client/PatchedLogsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,23 @@ public File getLogs(final LogsRequestBody logsRequestBody) throws ApiException {
* @return ApiResponse&lt;File&gt;
* @throws ApiException if fails to make API call
*/
public ApiResponse<File> getLogsWithHttpInfo(final LogsRequestBody logsRequestBody) throws ApiException {
public ApiResponse<File> getLogsWithHttpInfo(final LogsRequestBody logsRequestBody)
throws ApiException {
final HttpRequest.Builder localVarRequestBuilder = getLogsRequestBuilder(logsRequestBody);
try {
final HttpResponse<InputStream> localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
localVarRequestBuilder.build(), HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
memberVarResponseInterceptor.accept(localVarResponse);
}
if (isErrorResponse(localVarResponse)) {
throw new ApiException(localVarResponse.statusCode(),
throw new ApiException(
localVarResponse.statusCode(),
"getLogs call received non-success response",
localVarResponse.headers(),
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
localVarResponse.body() == null
? null
: new String(localVarResponse.body().readAllBytes()));
}

final File tmpFile = File.createTempFile("patched-logs-api", "response"); // CHANGED
Expand All @@ -88,10 +91,8 @@ public ApiResponse<File> getLogsWithHttpInfo(final LogsRequestBody logsRequestBo
FileUtils.copyInputStreamToFile(localVarResponse.body(), tmpFile); // CHANGED

return new ApiResponse<File>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
tmpFile // CHANGED
);
localVarResponse.statusCode(), localVarResponse.headers().map(), tmpFile // CHANGED
);
} catch (final IOException e) {
throw new ApiException(e);
} catch (final InterruptedException e) {
Expand All @@ -104,10 +105,12 @@ private Boolean isErrorResponse(final HttpResponse<InputStream> httpResponse) {
return httpResponse.statusCode() / 100 != 2;
}

private HttpRequest.Builder getLogsRequestBuilder(final LogsRequestBody logsRequestBody) throws ApiException {
private HttpRequest.Builder getLogsRequestBuilder(final LogsRequestBody logsRequestBody)
throws ApiException {
// verify the required parameter 'logsRequestBody' is set
if (logsRequestBody == null) {
throw new ApiException(400, "Missing the required parameter 'logsRequestBody' when calling getLogs");
throw new ApiException(
400, "Missing the required parameter 'logsRequestBody' when calling getLogs");
}

final HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
Expand All @@ -122,7 +125,8 @@ private HttpRequest.Builder getLogsRequestBuilder(final LogsRequestBody logsRequ

try {
final byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes(logsRequestBody);
localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody));
localVarRequestBuilder.method(
"POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody));
} catch (final IOException e) {
throw new ApiException(e);
}
Expand All @@ -134,5 +138,4 @@ private HttpRequest.Builder getLogsRequestBuilder(final LogsRequestBody logsRequ
}
return localVarRequestBuilder;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class AirbyteApiClientTest {
private static final int TEST_JITTER_INTERVAL_SECS = 1;
private static final int TEST_FINAL_INTERVAL_SECS = 1;
private static final int TEST_MAX_RETRIES = 2;

@Mock
private Callable mockCallable;

Expand All @@ -33,7 +34,12 @@ void ifSucceedShouldNotRetry() throws Exception {
mockCallable = mock(Callable.class);
when(mockCallable.call()).thenReturn("Success!");

AirbyteApiClient.retryWithJitter(mockCallable, "test", TEST_JITTER_INTERVAL_SECS, TEST_FINAL_INTERVAL_SECS, TEST_MAX_RETRIES);
AirbyteApiClient.retryWithJitter(
mockCallable,
"test",
TEST_JITTER_INTERVAL_SECS,
TEST_FINAL_INTERVAL_SECS,
TEST_MAX_RETRIES);

verify(mockCallable, times(1)).call();
}
Expand All @@ -44,27 +50,27 @@ void onlyRetryTillMaxRetries() throws Exception {
mockCallable = mock(Callable.class);
when(mockCallable.call()).thenThrow(new RuntimeException("Bomb!"));

AirbyteApiClient.retryWithJitter(mockCallable, "test", TEST_JITTER_INTERVAL_SECS, TEST_FINAL_INTERVAL_SECS, TEST_MAX_RETRIES);
AirbyteApiClient.retryWithJitter(
mockCallable,
"test",
TEST_JITTER_INTERVAL_SECS,
TEST_FINAL_INTERVAL_SECS,
TEST_MAX_RETRIES);

verify(mockCallable, times(TEST_MAX_RETRIES)).call();

}

@Test
@DisplayName("Should retry only if there are errors")
void onlyRetryOnErrors() throws Exception {
mockCallable = mock(Callable.class);
// Because we succeed on the second try, we should only call the method twice.
when(mockCallable.call())
.thenThrow(new RuntimeException("Bomb!"))
.thenReturn("Success!");
when(mockCallable.call()).thenThrow(new RuntimeException("Bomb!")).thenReturn("Success!");

AirbyteApiClient.retryWithJitter(mockCallable, "test", TEST_JITTER_INTERVAL_SECS, TEST_FINAL_INTERVAL_SECS, 3);
AirbyteApiClient.retryWithJitter(
mockCallable, "test", TEST_JITTER_INTERVAL_SECS, TEST_FINAL_INTERVAL_SECS, 3);

verify(mockCallable, times(2)).call();

}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ private CDKConstants() {
private static String getVersion() {
Properties prop = new Properties();

try (InputStream inputStream = CDKConstants.class.getClassLoader().getResourceAsStream("version.properties")) {
try (InputStream inputStream =
CDKConstants.class.getClassLoader().getResourceAsStream("version.properties")) {
prop.load(inputStream);
return prop.getProperty("version");
} catch (IOException e) {
throw new RuntimeException("Could not read version properties file", e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ void getVersion() {
void mustFail() {
fail("This is an intentionally failing test.");
}

}
17 changes: 11 additions & 6 deletions airbyte-commons-cli/src/main/java/io/airbyte/commons/cli/Clis.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public class Clis {
* @param options - expected options
* @return object with parsed values.
*/
public static CommandLine parse(final String[] args, final Options options, final CommandLineParser parser, final String commandLineSyntax) {
public static CommandLine parse(
final String[] args,
final Options options,
final CommandLineParser parser,
final String commandLineSyntax) {
final HelpFormatter helpFormatter = new HelpFormatter();

try {
Expand All @@ -35,11 +39,13 @@ public static CommandLine parse(final String[] args, final Options options, fina
}
}

public static CommandLine parse(final String[] args, final Options options, final String commandLineSyntax) {
public static CommandLine parse(
final String[] args, final Options options, final String commandLineSyntax) {
return parse(args, options, new DefaultParser(), commandLineSyntax);
}

public static CommandLine parse(final String[] args, final Options options, final CommandLineParser parser) {
public static CommandLine parse(
final String[] args, final Options options, final CommandLineParser parser) {
return parse(args, options, parser, null);
}

Expand All @@ -55,7 +61,8 @@ public static CommandLineParser getRelaxedParser() {
private static class RelaxedParser extends DefaultParser {

@Override
public CommandLine parse(final Options options, final String[] arguments) throws ParseException {
public CommandLine parse(final Options options, final String[] arguments)
throws ParseException {
final List<String> knownArgs = new ArrayList<>();
for (int i = 0; i < arguments.length; i++) {
if (options.hasOption(arguments[i])) {
Expand All @@ -67,7 +74,5 @@ public CommandLine parse(final Options options, final String[] arguments) throws
}
return super.parse(options, knownArgs.toArray(new String[0]));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ void testParseNonConforming() {
final Option optionB = Option.builder("b").required(true).hasArg(true).build();
final Options options = new Options().addOption(optionA).addOption(optionB);
final String[] args = {"-a", ALPHA, "-b", BETA, "-c", "charlie"};
assertThrows(IllegalArgumentException.class, () -> Clis.parse(args, options, new DefaultParser()));
assertThrows(
IllegalArgumentException.class, () -> Clis.parse(args, options, new DefaultParser()));
}

@Test
Expand All @@ -44,7 +45,9 @@ void testParseNonConformingWithSyntax() {
final Option optionB = Option.builder("b").required(true).hasArg(true).build();
final Options options = new Options().addOption(optionA).addOption(optionB);
final String[] args = {"-a", ALPHA, "-b", BETA, "-c", "charlie"};
assertThrows(IllegalArgumentException.class, () -> Clis.parse(args, options, new DefaultParser(), "search"));
assertThrows(
IllegalArgumentException.class,
() -> Clis.parse(args, options, new DefaultParser(), "search"));
}

@Test
Expand All @@ -57,5 +60,4 @@ void testRelaxedParser() {
assertEquals(ALPHA, parsed.getOptions()[0].getValue());
assertEquals(BETA, parsed.getOptions()[1].getValue());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,47 @@ public void initialize() {
* Downgrade a message from the most recent version to the target version by chaining all the
* required migrations
*/
public <PreviousVersion, CurrentVersion> PreviousVersion downgrade(final CurrentVersion message,
final Version target,
final Optional<ConfiguredAirbyteCatalog> configuredAirbyteCatalog) {
return migrationContainer.downgrade(message, target, (migration, msg) -> applyDowngrade(migration, msg, configuredAirbyteCatalog));
public <PreviousVersion, CurrentVersion> PreviousVersion downgrade(
final CurrentVersion message,
final Version target,
final Optional<ConfiguredAirbyteCatalog> configuredAirbyteCatalog) {
return migrationContainer.downgrade(
message,
target,
(migration, msg) -> applyDowngrade(migration, msg, configuredAirbyteCatalog));
}

/**
* Upgrade a message from the source version to the most recent version by chaining all the required
* migrations
*/
public <PreviousVersion, CurrentVersion> CurrentVersion upgrade(final PreviousVersion message,
final Version source,
final Optional<ConfiguredAirbyteCatalog> configuredAirbyteCatalog) {
return migrationContainer.upgrade(message, source, (migration, msg) -> applyUpgrade(migration, msg, configuredAirbyteCatalog));
public <PreviousVersion, CurrentVersion> CurrentVersion upgrade(
final PreviousVersion message,
final Version source,
final Optional<ConfiguredAirbyteCatalog> configuredAirbyteCatalog) {
return migrationContainer.upgrade(
message,
source,
(migration, msg) -> applyUpgrade(migration, msg, configuredAirbyteCatalog));
}

public Version getMostRecentVersion() {
return migrationContainer.getMostRecentVersion();
}

// Helper function to work around type casting
private static <PreviousVersion, CurrentVersion> PreviousVersion applyDowngrade(final AirbyteMessageMigration<PreviousVersion, CurrentVersion> migration,
final Object message,
final Optional<ConfiguredAirbyteCatalog> configuredAirbyteCatalog) {
private static <PreviousVersion, CurrentVersion> PreviousVersion applyDowngrade(
final AirbyteMessageMigration<PreviousVersion, CurrentVersion> migration,
final Object message,
final Optional<ConfiguredAirbyteCatalog> configuredAirbyteCatalog) {
return migration.downgrade((CurrentVersion) message, configuredAirbyteCatalog);
}

// Helper function to work around type casting
private static <PreviousVersion, CurrentVersion> CurrentVersion applyUpgrade(final AirbyteMessageMigration<PreviousVersion, CurrentVersion> migration,
final Object message,
final Optional<ConfiguredAirbyteCatalog> configuredAirbyteCatalog) {
private static <PreviousVersion, CurrentVersion> CurrentVersion applyUpgrade(
final AirbyteMessageMigration<PreviousVersion, CurrentVersion> migration,
final Object message,
final Optional<ConfiguredAirbyteCatalog> configuredAirbyteCatalog) {
return migration.upgrade((PreviousVersion) message, configuredAirbyteCatalog);
}

Expand All @@ -78,5 +88,4 @@ private static <PreviousVersion, CurrentVersion> CurrentVersion applyUpgrade(fin
Set<String> getMigrationKeys() {
return migrationContainer.getMigrationKeys();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public class AirbyteMessageSerDeProvider {
private final Map<String, AirbyteMessageDeserializer<?>> deserializers = new HashMap<>();
private final Map<String, AirbyteMessageSerializer<?>> serializers = new HashMap<>();

public AirbyteMessageSerDeProvider(final List<AirbyteMessageDeserializer<?>> deserializers,
final List<AirbyteMessageSerializer<?>> serializers) {
public AirbyteMessageSerDeProvider(
final List<AirbyteMessageDeserializer<?>> deserializers,
final List<AirbyteMessageSerializer<?>> serializers) {
deserializersToRegister = deserializers;
serializersToRegister = serializers;
}
Expand Down Expand Up @@ -68,8 +69,10 @@ void registerDeserializer(final AirbyteMessageDeserializer<?> deserializer) {
if (!deserializers.containsKey(key)) {
deserializers.put(key, deserializer);
} else {
throw new RuntimeException(String.format("Trying to register a deserializer for protocol version {} when {} already exists",
deserializer.getTargetVersion().serialize(), deserializers.get(key).getTargetVersion().serialize()));
throw new RuntimeException(String.format(
"Trying to register a deserializer for protocol version {} when {} already exists",
deserializer.getTargetVersion().serialize(),
deserializers.get(key).getTargetVersion().serialize()));
}
}

Expand All @@ -79,8 +82,10 @@ void registerSerializer(final AirbyteMessageSerializer<?> serializer) {
if (!serializers.containsKey(key)) {
serializers.put(key, serializer);
} else {
throw new RuntimeException(String.format("Trying to register a serializer for protocol version {} when {} already exists",
serializer.getTargetVersion().serialize(), serializers.get(key).getTargetVersion().serialize()));
throw new RuntimeException(String.format(
"Trying to register a serializer for protocol version {} when {} already exists",
serializer.getTargetVersion().serialize(),
serializers.get(key).getTargetVersion().serialize()));
}
}

Expand All @@ -95,5 +100,4 @@ Set<String> getDeserializerKeys() {
Set<String> getSerializerKeys() {
return serializers.keySet();
}

}
Loading
Loading