-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NOID] Fixes #4207: Integration Tests for Load Procedures with Cloud …
…Object Storage (#4226) * Fixes #4207: Integration Tests for Load Procedures with Cloud Object Storage * added google cloud tests * wip - adding other procs * cleanup * added jsonParams proc * fix tests * fix extended-it tests * cleanup * fix NoFileFound errors * fixed tests due to missing apoc config * added ignored export tests
- Loading branch information
Showing
42 changed files
with
2,620 additions
and
295 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
62 changes: 62 additions & 0 deletions
62
extended-it/src/test/java/apoc/azure/ArrowAzureStorageTest.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,62 @@ | ||
package apoc.azure; | ||
|
||
import apoc.export.arrow.ArrowTestUtil; | ||
import apoc.util.s3.S3BaseTest; | ||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.neo4j.configuration.GraphDatabaseInternalSettings; | ||
import org.neo4j.test.rule.DbmsRule; | ||
import org.neo4j.test.rule.ImpermanentDbmsRule; | ||
|
||
import java.util.Map; | ||
|
||
import static apoc.ApocConfig.APOC_EXPORT_FILE_ENABLED; | ||
import static apoc.ApocConfig.APOC_IMPORT_FILE_ENABLED; | ||
import static apoc.ApocConfig.apocConfig; | ||
import static apoc.export.arrow.ArrowTestUtil.initDbCommon; | ||
import static apoc.export.arrow.ArrowTestUtil.testImportCommon; | ||
import static apoc.export.arrow.ArrowTestUtil.testLoadArrow; | ||
|
||
@Ignore("This test won't work until the Azure Storage files will be correctly handled via FileUtils, placed in APOC Core") | ||
public class ArrowAzureStorageTest extends AzureStorageBaseTest { | ||
|
||
@Rule | ||
public DbmsRule db = new ImpermanentDbmsRule() | ||
.withSetting(GraphDatabaseInternalSettings.enable_experimental_cypher_versions, true); | ||
|
||
@Before | ||
public void beforeClass() { | ||
initDbCommon(db); | ||
apocConfig().setProperty(APOC_IMPORT_FILE_ENABLED, true); | ||
apocConfig().setProperty(APOC_EXPORT_FILE_ENABLED, true); | ||
} | ||
|
||
@Test | ||
public void testFileRoundtripWithLoadArrow() { | ||
String url = putToAzureStorageAndGetUrl("test_all.arrow"); | ||
|
||
String file = db.executeTransactionally("CALL apoc.export.arrow.all($url) YIELD file", | ||
Map.of("url", url), | ||
ArrowTestUtil::extractFileName); | ||
|
||
// check that the exported file is correct | ||
final String query = "CALL apoc.load.arrow($file, {})"; | ||
testLoadArrow(db, query, Map.of("file", file)); | ||
} | ||
|
||
|
||
@Test | ||
public void testFileRoundtripWithImportArrow() { | ||
db.executeTransactionally("CREATE (:Another {foo:1, listInt: [1,2]}), (:Another {bar:'Sam'})"); | ||
|
||
String url = putToAzureStorageAndGetUrl("test_all_import.arrow"); | ||
String file = db.executeTransactionally("CALL apoc.export.arrow.all($url) YIELD file", | ||
Map.of("url", url), | ||
ArrowTestUtil::extractFileName); | ||
|
||
// check that the exported file is correct | ||
testImportCommon(db, file, ArrowTestUtil.MAPPING_ALL); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
extended-it/src/test/java/apoc/azure/AzureStorageBaseTest.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,74 @@ | ||
package apoc.azure; | ||
|
||
import com.azure.core.util.Context; | ||
import com.azure.storage.blob.BlobClient; | ||
import com.azure.storage.blob.BlobContainerClient; | ||
import com.azure.storage.blob.BlobContainerClientBuilder; | ||
import com.azure.storage.blob.sas.BlobSasPermission; | ||
import com.azure.storage.blob.sas.BlobServiceSasSignatureValues; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.time.OffsetDateTime; | ||
import java.util.UUID; | ||
|
||
public class AzureStorageBaseTest { | ||
|
||
public static GenericContainer<?> azuriteContainer; | ||
public static BlobContainerClient containerClient; | ||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
DockerImageName azuriteImg = DockerImageName.parse("mcr.microsoft.com/azure-storage/azurite"); | ||
azuriteContainer = new GenericContainer<>(azuriteImg) | ||
.withExposedPorts(10000); | ||
|
||
azuriteContainer.start(); | ||
|
||
var accountName = "devstoreaccount1"; | ||
var accountKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="; | ||
var blobEndpoint = "http://%s:%d/%s".formatted(azuriteContainer.getHost(), azuriteContainer.getMappedPort(10000), accountName); | ||
var connectionString = "DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s;BlobEndpoint=%s;" | ||
.formatted(accountName, accountKey, blobEndpoint); | ||
|
||
containerClient = new BlobContainerClientBuilder() | ||
.connectionString(connectionString) | ||
.containerName("test-container") | ||
.buildClient(); | ||
containerClient.create(); | ||
} | ||
|
||
@AfterClass | ||
public static void teardown() { | ||
azuriteContainer.close(); | ||
} | ||
|
||
public static String putToAzureStorageAndGetUrl(String url) { | ||
try { | ||
File file = new File(url); | ||
byte[] content = FileUtils.readFileToByteArray(file); | ||
|
||
var blobClient = getBlobClient(content); | ||
BlobSasPermission permission = new BlobSasPermission().setReadPermission(true); | ||
OffsetDateTime expiryTime = OffsetDateTime.now().plusHours(1); | ||
String sasToken = blobClient.generateSas(new BlobServiceSasSignatureValues(expiryTime, permission), new Context("Azure-Storage-Log-String-To-Sign", "true")); | ||
return blobClient.getBlobUrl() + "?" + sasToken; | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static BlobClient getBlobClient(byte[] content) { | ||
var blobName = "blob-" + UUID.randomUUID(); | ||
var blobClient = containerClient.getBlobClient(blobName); | ||
blobClient.upload(new ByteArrayInputStream(content)); | ||
return blobClient; | ||
} | ||
|
||
} |
Oops, something went wrong.