Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rylern committed Sep 11, 2024
1 parent f2ae91b commit ed297c8
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 49 deletions.
19 changes: 4 additions & 15 deletions src/main/java/qupath/ext/omero/core/apis/ApisHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
public class ApisHandler implements AutoCloseable {

private static final Logger logger = LoggerFactory.getLogger(ApisHandler.class);
private static final int THUMBNAIL_SIZE = 256;
private static final int THUMBNAIL_CACHE_SIZE = 1000;
private static final Map<String, PixelType> PIXEL_TYPE_MAP = Map.of(
"uint8", PixelType.UINT8,
Expand All @@ -67,12 +66,11 @@ public class ApisHandler implements AutoCloseable {
private final WebGatewayApi webGatewayApi;
private final IViewerApi iViewerApi;
private final BooleanProperty areOrphanedImagesLoading = new SimpleBooleanProperty(false);
private final Cache<IdSizeWrapper, CompletableFuture<Optional<BufferedImage>>> thumbnailsCache = CacheBuilder.newBuilder()
private final Cache<Long, CompletableFuture<Optional<BufferedImage>>> thumbnailsCache = CacheBuilder.newBuilder()
.maximumSize(THUMBNAIL_CACHE_SIZE)
.build();
private final Map<Class<? extends RepositoryEntity>, BufferedImage> omeroIconsCache = new ConcurrentHashMap<>();
private final boolean canSkipAuthentication;
private record IdSizeWrapper(long id, int size) {}

private ApisHandler(URI host, JsonApi jsonApi, boolean canSkipAuthentication) {
this.host = host;
Expand Down Expand Up @@ -493,29 +491,20 @@ public CompletableFuture<Optional<BufferedImage>> getOmeroIcon(Class<? extends R
}
}

/**
* {@link #getThumbnail(long, int)} with a size of
* {@link #THUMBNAIL_SIZE}.
*/
public CompletableFuture<Optional<BufferedImage>> getThumbnail(long id) {
return getThumbnail(id, THUMBNAIL_SIZE);
}

/**
* See {@link WebGatewayApi#getThumbnail(long)}.
* Thumbnails are cached in a cache of size {@link #THUMBNAIL_CACHE_SIZE}.
*/
public CompletableFuture<Optional<BufferedImage>> getThumbnail(long id, int size) {
public CompletableFuture<Optional<BufferedImage>> getThumbnail(long id) {
try {
IdSizeWrapper key = new IdSizeWrapper(id, size);
CompletableFuture<Optional<BufferedImage>> request = thumbnailsCache.get(
key,
id,
() -> webGatewayApi.getThumbnail(id)
);

request.thenAccept(response -> {
if (response.isEmpty()) {
thumbnailsCache.invalidate(key);
thumbnailsCache.invalidate(id);
}
});
return request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,6 @@ protected BufferedImage readTile(TileRequest tileRequest) throws IOException {
return pixelAPIReader.readTile(tileRequest);
}

@Override
public BufferedImage getDefaultThumbnail(int z, int t) throws IOException {
Optional<BufferedImage> thumbnail = Optional.empty();

if (isRGB()) {
try {
thumbnail = client.getApisHandler().getThumbnail(
id,
Math.max(originalMetadata.getLevel(0).getWidth(), originalMetadata.getLevel(0).getHeight())
).get();
} catch (InterruptedException | ExecutionException e) {
throw new IOException(e);
}
}

if (thumbnail.isPresent()) {
return thumbnail.get();
} else {
return super.getDefaultThumbnail(z, t);
}
}

@Override
protected ImageServerBuilder.ServerBuilder<BufferedImage> createServerBuilder() {
return ImageServerBuilder.DefaultImageServerBuilder.createInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Image(WebClient client, URI imageUri) throws IOException {
image.ifPresent(value -> name.setText(value.getLabel().get()))
));

client.getApisHandler().getThumbnail(imageID.getAsLong(), (int) thumbnail.getWidth()).thenAccept(thumbnail -> Platform.runLater(() ->
client.getApisHandler().getThumbnail(imageID.getAsLong()).thenAccept(thumbnail -> Platform.runLater(() ->
thumbnail.ifPresent(bufferedImage -> UiUtilities.paintBufferedImageOnCanvas(bufferedImage, this.thumbnail))
));
}
Expand Down
11 changes: 0 additions & 11 deletions src/test/java/qupath/ext/omero/core/apis/TestApisHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,17 +540,6 @@ void Check_Image_Thumbnail() throws ExecutionException, InterruptedException {
Assertions.assertNotNull(image);
}

@Test
void Check_Image_Thumbnail_With_Specific_Size() throws ExecutionException, InterruptedException {
long imageId = OmeroServer.getComplexImage().getId();
int size = 30;

BufferedImage image = apisHandler.getThumbnail(imageId, size).get().orElse(null);

Assertions.assertNotNull(image);
Assertions.assertEquals(size, Math.max(image.getWidth(), image.getHeight()));
}

@Test
void Check_Image_Thumbnail_With_Invalid_Image_ID() throws ExecutionException, InterruptedException {
long invalidImageID = -1;
Expand Down
5 changes: 5 additions & 0 deletions src/test/resources/omero-web/installPixelBufferMs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
cd /
tar -xvkf /tmp/OMERO.tar.gz

# See https://stackoverflow.com/a/78693402
# This should be needed as long as the base image is the deprecated CentOS7
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

# Build the pixel buffer microservice
yum install git java-devel -y
git clone https://github.com/glencoesoftware/omero-ms-pixel-buffer
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ docker run -d \
-e ROOTPASS=password \
-p 4064:4064 \
--privileged \
--platform linux/x86_64 \
--mount type=bind,src=$SCRIPT_DIR"/omero-server",target=/resources \
openmicroscopy/omero-server

Expand Down

0 comments on commit ed297c8

Please sign in to comment.