-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from groldan/bug/azure_blob_store
Fix AzureBlobStore regression due to wrong netty version after dependencyConvergence maven rule
- Loading branch information
Showing
8 changed files
with
209 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
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
119 changes: 119 additions & 0 deletions
119
...c/backends/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzureBlobStoreTest.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,119 @@ | ||
/* | ||
* (c) 2023 Open Source Geospatial Foundation - all rights reserved This code is licensed under the | ||
* GPL 2.0 license, available at the root application directory. | ||
*/ | ||
package org.geoserver.cloud.gwc.config.blobstore; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.geowebcache.GeoWebCacheEnvironment; | ||
import org.geowebcache.GeoWebCacheExtensions; | ||
import org.geowebcache.azure.AzureBlobStore; | ||
import org.geowebcache.azure.AzureBlobStoreInfo; | ||
import org.geowebcache.io.ByteArrayResource; | ||
import org.geowebcache.io.Resource; | ||
import org.geowebcache.layer.TileLayer; | ||
import org.geowebcache.layer.TileLayerDispatcher; | ||
import org.geowebcache.locks.MemoryLockProvider; | ||
import org.geowebcache.storage.BlobStore; | ||
import org.geowebcache.storage.StorageException; | ||
import org.geowebcache.storage.TileObject; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.context.support.StaticApplicationContext; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Verify {@link AzureBlobStore} works by connecting to an Azurite container | ||
* | ||
* @see AzuriteContainer | ||
*/ | ||
@Testcontainers | ||
public class AzureBlobStoreTest { | ||
|
||
@Container static AzuriteContainer azurite = new AzuriteContainer(); | ||
|
||
protected AzureBlobStoreInfo newAzureBlobStoreInfo() { | ||
AzureBlobStoreInfo bsi = new AzureBlobStoreInfo(); | ||
|
||
String accountName = azurite.getAccountName(); | ||
String accountKey = azurite.getAccountKey(); | ||
String blobsUrl = azurite.getBlobsUrl(); | ||
|
||
bsi.setAccountName(accountName); | ||
bsi.setAccountKey(accountKey); | ||
bsi.setServiceURL(blobsUrl); | ||
bsi.setUseHTTPS(false); | ||
bsi.setContainer("azureblobstoretest"); | ||
bsi.setName("AzureBlobStoreTest"); | ||
bsi.setEnabled(true); | ||
// bsi.setPrefix("/gwc/"); | ||
return bsi; | ||
} | ||
|
||
static StaticApplicationContext stubAppContext; | ||
|
||
static @BeforeAll void setUpContext() { | ||
GeoWebCacheExtensions extensions = new GeoWebCacheExtensions(); | ||
GeoWebCacheEnvironment environment = new GeoWebCacheEnvironment(); | ||
|
||
stubAppContext = new StaticApplicationContext(); | ||
stubAppContext.registerBean(GeoWebCacheExtensions.class, () -> extensions); | ||
stubAppContext.registerBean(GeoWebCacheEnvironment.class, () -> environment); | ||
stubAppContext.refresh(); | ||
} | ||
|
||
static @AfterAll void closeContext() { | ||
stubAppContext.close(); | ||
} | ||
|
||
public @Test void createBlobStore() throws StorageException { | ||
AzureBlobStoreInfo info = newAzureBlobStoreInfo(); | ||
BlobStore store = | ||
info.createInstance(mock(TileLayerDispatcher.class), new MemoryLockProvider()); | ||
assertThat(store).isInstanceOf(AzureBlobStore.class); | ||
} | ||
|
||
public @Test void testPutGet() throws Exception { | ||
TileLayerDispatcher layers = mock(TileLayerDispatcher.class); | ||
|
||
AzureBlobStoreInfo info = newAzureBlobStoreInfo(); | ||
AzureBlobStore store = | ||
(AzureBlobStore) info.createInstance(layers, new MemoryLockProvider()); | ||
|
||
final String layerName = "FakeLayer"; | ||
final long[] xyz = new long[] {0, 0, 0}; | ||
final String gridSetId = "EPSG:3857"; | ||
final String format = "image/png"; | ||
final Map<String, String> parameters = null; | ||
byte[] contents = new byte[] {1, 2, 3, 4, 5, 6, 7}; | ||
final Resource blob = new ByteArrayResource(contents); | ||
|
||
TileLayer tileLayer = mock(TileLayer.class); | ||
when(tileLayer.getId()).thenReturn(layerName); | ||
when(layers.getTileLayer(eq(layerName))).thenReturn(tileLayer); | ||
|
||
TileObject tile = | ||
TileObject.createCompleteTileObject( | ||
layerName, xyz, gridSetId, format, parameters, blob); | ||
store.put(tile); | ||
|
||
TileObject query = | ||
TileObject.createQueryTileObject(layerName, xyz, gridSetId, format, parameters); | ||
|
||
// can't really test get, see https://github.com/Azure/Azurite/issues/217 | ||
if (true) return; | ||
assertThat(store.get(query)).isTrue(); | ||
assertThat(query.getBlob()).isNotNull(); | ||
byte[] readContents = IOUtils.toByteArray(query.getBlob().getInputStream()); | ||
assertThat(readContents).isEqualTo(contents); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...gwc/backends/src/test/java/org/geoserver/cloud/gwc/config/blobstore/AzuriteContainer.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,50 @@ | ||
package org.geoserver.cloud.gwc.config.blobstore; | ||
|
||
import lombok.Getter; | ||
import lombok.NonNull; | ||
|
||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
/** | ||
* {@link Testcontainers} container for AWS Azurite blobstore test environment. | ||
* | ||
* <p>Runs the <a href= | ||
* "https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json&bc=%2Fazure%2Fstorage%2Fblobs%2Fbreadcrumb%2Ftoc.json&tabs=docker-hub">Azurite | ||
* emulator</a> for local Azure Storage development with testcontainers. | ||
* | ||
* <p>Azurite accepts the same well-known account and key used by the legacy Azure Storage Emulator. | ||
* | ||
* <ul> | ||
* <li>Account name: {@code devstoreaccount1} | ||
* <li>Account key: {@code | ||
* Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==} | ||
* </ul> | ||
*/ | ||
public class AzuriteContainer extends GenericContainer<AzuriteContainer> { | ||
|
||
private static final @NonNull DockerImageName IMAGE_NAME = | ||
DockerImageName.parse("mcr.microsoft.com/azure-storage/azurite:latest"); | ||
|
||
public final @Getter String accountName = "devstoreaccount1"; | ||
public final @Getter String accountKey = | ||
"Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="; | ||
|
||
private final int blobsPort = 10_000; | ||
|
||
public AzuriteContainer() { | ||
super(IMAGE_NAME); | ||
super.setWaitStrategy(Wait.forListeningPort()); | ||
super.addExposedPort(blobsPort); | ||
} | ||
|
||
public int getBlobsPort() { | ||
return super.getMappedPort(blobsPort); | ||
} | ||
|
||
public String getBlobsUrl() { | ||
return "http://localhost:%d/%s".formatted(getBlobsPort(), getAccountName()); | ||
} | ||
} |
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,16 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger [%X{instance-id}] %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
|
||
<logger name="org.springframework.test" level="ERROR" /> | ||
<logger name="org.springframework.boot.test" level="ERROR" /> | ||
<logger name="com.microsoft.azure.storage.blob" level="WARN" /> | ||
|
||
</configuration> |
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