Skip to content

Commit

Permalink
[FLINK-31876][QS] Migrate flink-queryable-state-runtime tests to JUnit5
Browse files Browse the repository at this point in the history
  • Loading branch information
fredia authored and reswqa committed May 12, 2023
1 parent 2d87362 commit 7f4e834
Show file tree
Hide file tree
Showing 15 changed files with 690 additions and 583 deletions.
6 changes: 6 additions & 0 deletions flink-queryable-state/flink-queryable-state-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ under the License.
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<excludes>
<!-- test-jar is still used by JUnit4 modules -->
<exclude>META-INF/services/org.junit.jupiter.api.extension.Extension</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,24 @@
import org.apache.flink.runtime.highavailability.HighAvailabilityServices;
import org.apache.flink.runtime.jobmaster.KvStateLocationOracle;
import org.apache.flink.runtime.query.KvStateLocation;
import org.apache.flink.util.TestLogger;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.net.InetAddress;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

/** Tests for the {@link KvStateClientProxyImpl}. */
public class KvStateClientProxyImplTest extends TestLogger {
class KvStateClientProxyImplTest {

private KvStateClientProxyImpl kvStateClientProxy;

@Before
public void setup() {
@BeforeEach
void setup() {
kvStateClientProxy =
new KvStateClientProxyImpl(
InetAddress.getLoopbackAddress().getHostName(),
Expand All @@ -53,14 +50,14 @@ public void setup() {
new DisabledKvStateRequestStats());
}

@After
public void shutdown() {
@AfterEach
void shutdown() {
kvStateClientProxy.shutdown();
}

/** Tests that we can set and retrieve the {@link KvStateLocationOracle}. */
@Test
public void testKvStateLocationOracle() {
void testKvStateLocationOracle() {
final JobID jobId1 = new JobID();
final TestingKvStateLocationOracle kvStateLocationOracle1 =
new TestingKvStateLocationOracle();
Expand All @@ -70,34 +67,32 @@ public void testKvStateLocationOracle() {
new TestingKvStateLocationOracle();
kvStateClientProxy.updateKvStateLocationOracle(jobId2, kvStateLocationOracle2);

assertThat(kvStateClientProxy.getKvStateLocationOracle(new JobID()), nullValue());
assertThat(kvStateClientProxy.getKvStateLocationOracle(new JobID())).isNull();

assertThat(
kvStateClientProxy.getKvStateLocationOracle(jobId1),
equalTo(kvStateLocationOracle1));
assertThat(
kvStateClientProxy.getKvStateLocationOracle(jobId2),
equalTo(kvStateLocationOracle2));
assertThat(kvStateClientProxy.getKvStateLocationOracle(jobId1))
.isEqualTo(kvStateLocationOracle1);
assertThat(kvStateClientProxy.getKvStateLocationOracle(jobId2))
.isEqualTo(kvStateLocationOracle2);

kvStateClientProxy.updateKvStateLocationOracle(jobId1, null);
assertThat(kvStateClientProxy.getKvStateLocationOracle(jobId1), nullValue());
assertThat(kvStateClientProxy.getKvStateLocationOracle(jobId1)).isNull();
}

/**
* Tests that {@link KvStateLocationOracle} registered under {@link
* HighAvailabilityServices#DEFAULT_JOB_ID} will be used for all requests.
*/
@Test
public void testLegacyCodePathPreference() {
void testLegacyCodePathPreference() {
final TestingKvStateLocationOracle kvStateLocationOracle =
new TestingKvStateLocationOracle();
kvStateClientProxy.updateKvStateLocationOracle(
HighAvailabilityServices.DEFAULT_JOB_ID, kvStateLocationOracle);
final JobID jobId = new JobID();
kvStateClientProxy.updateKvStateLocationOracle(jobId, new TestingKvStateLocationOracle());

assertThat(
kvStateClientProxy.getKvStateLocationOracle(jobId), equalTo(kvStateLocationOracle));
assertThat(kvStateClientProxy.getKvStateLocationOracle(jobId))
.isEqualTo(kvStateLocationOracle);
}

/** Testing implementation of {@link KvStateLocationOracle}. */
Expand Down
Loading

0 comments on commit 7f4e834

Please sign in to comment.