Skip to content

Commit

Permalink
FIX #226 : Upgrade to RxJava 3 -- fix tests
Browse files Browse the repository at this point in the history
Use blockingSubscribe()
  • Loading branch information
ghusta authored and Guillaume Husta committed May 26, 2021
1 parent a59e162 commit fe4dc95
Showing 1 changed file with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import fr.husta.android.dockersearch.docker.model.ContainerRepositoryTagV2;
import fr.husta.android.dockersearch.docker.model.RepositoryTagV2;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.disposables.Disposable;

import static com.google.common.truth.Truth.assertThat;

Expand All @@ -20,7 +19,7 @@ public class DockerRegistryClientTest
private static final long _45_SECONDS_IN_MILLIS = 45 * 1000L;

@Test(timeout = _30_SECONDS_IN_MILLIS)
public void searchImagesAsync() throws Exception
public void searchImagesAsync()
{
DockerRegistryClient dockerRegistryClient = new DockerRegistryClient();
String term;
Expand All @@ -34,7 +33,7 @@ public void searchImagesAsync() throws Exception
}

@Test(timeout = _30_SECONDS_IN_MILLIS)
public void listTagsV2() throws Exception
public void listTagsV2()
{
long start = System.currentTimeMillis();
DockerRegistryClient dockerRegistryClient = new DockerRegistryClient();
Expand All @@ -44,7 +43,7 @@ public void listTagsV2() throws Exception
repo = "library/tomcat";
// ContainerRepositoryTagV2 containerRepositoryTagV2 = dockerRegistryClient.listTagsV2(repo);
AtomicReference<ContainerRepositoryTagV2> containerRepositoryTagV2 = new AtomicReference<>();
Disposable disposable = dockerRegistryClient.listTagsV2(repo).subscribe(containerRepositoryTagV2::set);
dockerRegistryClient.listTagsV2(repo).blockingSubscribe(containerRepositoryTagV2::set);
List<RepositoryTagV2> repositoryTags = containerRepositoryTagV2.get().getTags();

long end = System.currentTimeMillis();
Expand All @@ -55,12 +54,10 @@ public void listTagsV2() throws Exception
RepositoryTagV2 firstTag = repositoryTags.get(0);
System.out.println(String.format("%s / %,d bytes / %s",
firstTag.getName(), firstTag.getFullSize(), firstTag.getLastUpdated()));

disposable.dispose();
}

@Test(timeout = _30_SECONDS_IN_MILLIS)
public void listTagsV2_Jenkins() throws Exception
public void listTagsV2_Jenkins()
{
long start = System.currentTimeMillis();
DockerRegistryClient dockerRegistryClient = new DockerRegistryClient();
Expand All @@ -69,20 +66,18 @@ public void listTagsV2_Jenkins() throws Exception
// repo = "tomcat";
repo = "library/jenkins";
AtomicReference<ContainerRepositoryTagV2> containerRepositoryTagV2 = new AtomicReference<>();
Disposable disposable = dockerRegistryClient.listTagsV2(repo).subscribe(containerRepositoryTagV2::set);
dockerRegistryClient.listTagsV2(repo).blockingSubscribe(containerRepositoryTagV2::set);
List<RepositoryTagV2> repositoryTags = containerRepositoryTagV2.get().getTags();

System.out.println("Page count = " + repositoryTags.size());
assertThat(repositoryTags.size()).isGreaterThan(1);
RepositoryTagV2 firstTag = repositoryTags.get(0);
System.out.println(String.format("%s / %,d bytes / %s",
firstTag.getName(), firstTag.getFullSize(), firstTag.getLastUpdated()));

disposable.dispose();
}

@Test(timeout = _30_SECONDS_IN_MILLIS)
public void listTagsV2_pageFull() throws Exception
public void listTagsV2_pageFull()
{
long start = System.currentTimeMillis();
DockerRegistryClient dockerRegistryClient = new DockerRegistryClient();
Expand All @@ -92,7 +87,7 @@ public void listTagsV2_pageFull() throws Exception
repo = "library/tomcat";
int pageSize = 5;
AtomicReference<ContainerRepositoryTagV2> containerRepositoryTagV2 = new AtomicReference<>();
Disposable disposable = dockerRegistryClient.listTagsV2(repo, 1, pageSize).subscribe(containerRepositoryTagV2::set);
dockerRegistryClient.listTagsV2(repo, 1, pageSize).blockingSubscribe(containerRepositoryTagV2::set);
List<RepositoryTagV2> repositoryTags = containerRepositoryTagV2.get().getTags();
assertThat(containerRepositoryTagV2.get().getPreviousUrl()).isNull();
assertThat(containerRepositoryTagV2.get().getNextUrl()).isNotNull();
Expand All @@ -106,12 +101,10 @@ public void listTagsV2_pageFull() throws Exception
RepositoryTagV2 firstTag = repositoryTags.get(0);
System.out.println(String.format("%s / %,d bytes / %s",
firstTag.getName(), firstTag.getFullSize(), firstTag.getLastUpdated()));

disposable.dispose();
}

@Test(timeout = _30_SECONDS_IN_MILLIS)
public void listTagsV2_lastPage() throws Exception
public void listTagsV2_lastPage()
{
long start = System.currentTimeMillis();
DockerRegistryClient dockerRegistryClient = new DockerRegistryClient();
Expand All @@ -121,7 +114,7 @@ public void listTagsV2_lastPage() throws Exception
int pageSize = 5;
// 1st request
AtomicReference<ContainerRepositoryTagV2> containerRepositoryTagV2 = new AtomicReference<>();
Disposable disposable = dockerRegistryClient.listTagsV2(repo, 1, pageSize).subscribe(containerRepositoryTagV2::set);
dockerRegistryClient.listTagsV2(repo, 1, pageSize).blockingSubscribe(containerRepositoryTagV2::set);
List<RepositoryTagV2> repositoryTags = containerRepositoryTagV2.get().getTags();
assertThat(containerRepositoryTagV2.get().getPreviousUrl()).isNull();
assertThat(containerRepositoryTagV2.get().getNextUrl()).isNotNull();
Expand All @@ -136,7 +129,7 @@ public void listTagsV2_lastPage() throws Exception

// 2nd request
AtomicReference<ContainerRepositoryTagV2> containerRepositoryTagV2_lastPage = new AtomicReference<>();
Disposable disposable2 = dockerRegistryClient.listTagsV2(repo, lastPage, pageSize).subscribe(containerRepositoryTagV2_lastPage::set);
dockerRegistryClient.listTagsV2(repo, lastPage, pageSize).blockingSubscribe(containerRepositoryTagV2_lastPage::set);
repositoryTags = containerRepositoryTagV2_lastPage.get().getTags();
assertThat(containerRepositoryTagV2_lastPage.get().getPreviousUrl()).isNotNull();
assertThat(containerRepositoryTagV2_lastPage.get().getNextUrl()).isNull();
Expand All @@ -145,9 +138,6 @@ public void listTagsV2_lastPage() throws Exception
RepositoryTagV2 lastTag = repositoryTags.get(repositoryTags.size() - 1);
System.out.println(String.format("%s / %,d bytes / %s",
lastTag.getName(), lastTag.getFullSize(), lastTag.getLastUpdated()));

disposable.dispose();
disposable2.dispose();
}

}

0 comments on commit fe4dc95

Please sign in to comment.