-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor MigrationAcceptanceTest to test for major version bumps (#8154)
- Loading branch information
Showing
10 changed files
with
316 additions
and
161 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
airbyte-commons/src/main/java/io/airbyte/commons/concurrency/WaitingUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.commons.concurrency; | ||
|
||
import static java.lang.Thread.sleep; | ||
|
||
import java.time.Duration; | ||
import java.util.function.Supplier; | ||
|
||
public class WaitingUtils { | ||
|
||
/** | ||
* Wait for a condition or timeout. | ||
* | ||
* @param interval - frequency with which condition and timeout should be checked. | ||
* @param timeout - how long to wait in total | ||
* @param condition - supplier that returns whether the condition has been met. | ||
* @return true if condition was met before the timeout was reached, otherwise false. | ||
*/ | ||
@SuppressWarnings("BusyWait") | ||
public static boolean waitForCondition(final Duration interval, final Duration timeout, final Supplier<Boolean> condition) { | ||
Duration timeWaited = Duration.ZERO; | ||
while (true) { | ||
if (condition.get()) { | ||
return true; | ||
} | ||
|
||
if (timeout.minus(timeWaited).isNegative()) { | ||
return false; | ||
} | ||
|
||
try { | ||
sleep(interval.toMillis()); | ||
} catch (final InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
timeWaited = timeWaited.plus(interval); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
airbyte-commons/src/main/java/io/airbyte/commons/util/MoreProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.commons.util; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
public class MoreProperties { | ||
|
||
/** | ||
* Read an .env file into a Properties object. | ||
* | ||
* @param envFile - .env file to read | ||
* @return properties object parsed from the contents of the .env | ||
* @throws IOException throws an exception if there are errors while reading the file. | ||
*/ | ||
public static Properties envFileToProperties(final File envFile) throws IOException { | ||
final Properties prop = new Properties(); | ||
prop.load(new FileInputStream(envFile)); | ||
return prop; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
airbyte-commons/src/test/java/io/airbyte/commons/concurrency/WaitingUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.commons.concurrency; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.time.Duration; | ||
import java.util.function.Supplier; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class WaitingUtilsTest { | ||
|
||
@SuppressWarnings("unchecked") | ||
@Test | ||
void testWaitForConditionConditionMet() { | ||
final Supplier<Boolean> condition = mock(Supplier.class); | ||
when(condition.get()) | ||
.thenReturn(false) | ||
.thenReturn(false) | ||
.thenReturn(true); | ||
assertTrue(WaitingUtils.waitForCondition(Duration.ofMillis(1), Duration.ofMillis(5), condition)); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Test | ||
void testWaitForConditionTimeout() { | ||
final Supplier<Boolean> condition = mock(Supplier.class); | ||
when(condition.get()).thenReturn(false); | ||
assertFalse(WaitingUtils.waitForCondition(Duration.ofMillis(1), Duration.ofMillis(5), condition)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
airbyte-commons/src/test/java/io/airbyte/commons/util/MorePropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.commons.util; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import io.airbyte.commons.io.IOs; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class MorePropertiesTest { | ||
|
||
@Test | ||
void testEnvFileToProperties() throws IOException { | ||
final String envFileContents = "OPTION1=hello\n" | ||
+ "OPTION2=2\n" | ||
+ "OPTION3=\n"; | ||
final File envFile = File.createTempFile("properties-test", ".env"); | ||
IOs.writeFile(envFile.toPath(), envFileContents); | ||
|
||
final Properties actual = MoreProperties.envFileToProperties(envFile); | ||
final Properties expected = new Properties(); | ||
expected.put("OPTION1", "hello"); | ||
expected.put("OPTION2", "2"); | ||
expected.put("OPTION3", ""); | ||
|
||
assertEquals(expected, actual); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.