-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reproduce Azure/azure-sdk-for-java#19612
- Loading branch information
Showing
4 changed files
with
248 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Maven | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
release.properties | ||
|
||
# Eclipse | ||
.project | ||
.classpath | ||
.settings/ | ||
bin/ | ||
|
||
# IDEA | ||
.idea | ||
*.ipr | ||
*.iml | ||
*.iws | ||
|
||
# NetBeans | ||
nb-configuration.xml | ||
|
||
# KDE | ||
.directory | ||
|
||
# OSX | ||
.DS_Store |
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,14 @@ | ||
= A reproducer for https://github.com/Azure/azure-sdk-for-java/issues/19612 | ||
|
||
To run the tests, you need to pass your Azure ceredentials via environment variables: | ||
|
||
[source,shell] | ||
---- | ||
export AZURE_STORAGE_ACCOUNT_NAME=my-account-name | ||
export AZURE_STORAGE_ACCOUNT_KEY=my-account-key | ||
# Then you can run the tests | ||
mvn test | ||
---- | ||
|
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,104 @@ | ||
<!-- | ||
Copyright 2019 the original author or authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.acme</groupId> | ||
<artifactId>reproducer-19612</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<azure-sdk-bom.version>1.0.2</azure-sdk-bom.version> | ||
|
||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
|
||
<maven-clean-plugin.version>2.5</maven-clean-plugin.version> | ||
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version> | ||
<maven-install-plugin.version>2.4</maven-install-plugin.version> | ||
<maven-resources-plugin.version>2.6</maven-resources-plugin.version> | ||
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.azure</groupId> | ||
<artifactId>azure-sdk-bom</artifactId> | ||
<version>${azure-sdk-bom.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.azure</groupId> | ||
<artifactId>azure-storage-file-datalake</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.6.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>3.19.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>${maven-clean-plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${maven-compiler-plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>${maven-install-plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>${maven-resources-plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${maven-surefire-plugin.version}</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
|
||
</project> |
102 changes: 102 additions & 0 deletions
102
src/test/java/org/acme/i19612/ReproduceIssue19612Test.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,102 @@ | ||
/* | ||
* Copyright 2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.acme.i19612; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Objects; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.azure.storage.common.StorageSharedKeyCredential; | ||
import com.azure.storage.file.datalake.DataLakeFileClient; | ||
import com.azure.storage.file.datalake.DataLakeServiceClient; | ||
import com.azure.storage.file.datalake.DataLakeServiceClientBuilder; | ||
|
||
public class ReproduceIssue19612Test { | ||
static final int randomSuffix = (int)(Math.random() * 1000); | ||
static final String fsName = "testfs"+ randomSuffix; | ||
static final String fileName = "file" + randomSuffix + ".txt"; | ||
static final byte[] content = "Hello world".getBytes(StandardCharsets.UTF_8); | ||
|
||
static DataLakeServiceClient client; | ||
static DataLakeFileClient fClient; | ||
@BeforeAll | ||
static void beforeAll() { | ||
StorageSharedKeyCredential creds = credentials(); | ||
String endpoint = "https://" + creds.getAccountName() + ".dfs.core.windows.net"; | ||
client = new DataLakeServiceClientBuilder() | ||
.credential(creds) | ||
.endpoint(endpoint) | ||
.buildClient(); | ||
client.createFileSystem(fsName); | ||
|
||
fClient = client.getFileSystemClient(fsName).getFileClient(fileName); | ||
fClient.upload(new ByteArrayInputStream(content), content.length); | ||
|
||
} | ||
|
||
@AfterAll | ||
static void cleanup() { | ||
client.deleteFileSystem(fsName); | ||
} | ||
|
||
@Test | ||
void openQueryInputStream() throws IOException { | ||
|
||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
String query = "SELECT * from BlobStorage"; | ||
try (InputStream in = fClient.openQueryInputStream(query)) { | ||
int c; | ||
while ((c = in.read()) >= 0) { | ||
baos.write(c); | ||
} | ||
} | ||
|
||
byte[] actual = baos.toByteArray(); | ||
// this fails, see https://github.com/Azure/azure-sdk-for-java/issues/19612 | ||
Assertions.assertThat(actual).containsExactly(content); | ||
} | ||
|
||
|
||
@Test | ||
void read() throws IOException { | ||
|
||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
|
||
// This works as expected | ||
fClient.read(baos); | ||
|
||
byte[] actual = baos.toByteArray(); | ||
Assertions.assertThat(actual).containsExactly(content); | ||
} | ||
|
||
static StorageSharedKeyCredential credentials() { | ||
final String azureStorageAccountName = Objects.requireNonNull(System.getenv("AZURE_STORAGE_ACCOUNT_NAME"), | ||
"Set AZURE_STORAGE_ACCOUNT_NAME env var"); | ||
final String azureStorageAccountKey = Objects.requireNonNull(System.getenv("AZURE_STORAGE_ACCOUNT_KEY"), | ||
"Set AZURE_STORAGE_ACCOUNT_KEY env var"); | ||
|
||
return new StorageSharedKeyCredential(azureStorageAccountName, azureStorageAccountKey); | ||
|
||
} | ||
} |