Skip to content

Commit

Permalink
Reconfigure MantaClientIT to incorporate #507, #539
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwin A Nair committed Jul 5, 2019
2 parents 9e2f780 + ed0f8e1 commit 9b874b9
Show file tree
Hide file tree
Showing 24 changed files with 410 additions and 197 deletions.
42 changes: 38 additions & 4 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,50 @@ property or `MANTA_IT_NO_CLEANUP` environment variable.

# Running Tests

Run `mvn verify` from the project root to run all tests. Some Maven goals will
not work
Run `mvn verify` from the project root to run all tests. Some Maven goals will not work.

While the Java Cryptography Extensions are expected to be installed, it is
possible torun a subset of the test suite by adding
`-DexcludedGroups=unlimited-crypto`, e.g.:
possible to run a subset of the test suite by adding
`-DexcludedGroups=unlimited-crypto` or `-Dgroups=headers,error`, e.g.
```
mvn test -DexcludedGroups=unlimited-crypto
mvn verify -Dgroups=headers,error
```

Also, if we are running a defined TestNG group, invoke
`-Dgroups=headers`, e.g:

```
mvn clean verify -Dgroups=headers
```

Note: Since we have transitioned from wildcard to explicit test definition (i.e `package-level`
to `class-level` hierarchy), engineers are required to add integration-tests in `testng-it.xml` file
complying with the nature of their corresponding TestNG groups. For instance, if we create a new
integration-test `ExampleHttpHeadersIT.java` for `headers`, that test will be defined under:
```
<test name="Manta Client Http Headers Tests">
<groups>
<define name="headers" />
</groups>
<classes>
<class name="com.joyent.manta.http.MantaHttpHeadersIT" />
<class name="com.joyent.manta.http.ExampleHttpHeadersIT" />
</classes>
</test>
```

## Dry run

The following invocation will print a list of which integration tests would run and their relevant
parameters::

```
mvn verify -Dit.dryRun=true
```

Note: This feature is invalid for unit tests.

# Writing Tests

The `java-manta-client` module contains unit tests. Integration tests generally
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2017, Joyent, Inc. All rights reserved.
* Copyright (c) 2015-2019, Joyent, Inc. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -29,10 +29,8 @@
/**
* Tests for verifying the correct functioning of making remote requests
* against Manta directories.
*
* @author <a href="https://github.com/dekobon">Elijah Zupancic</a>
*/
@Test(groups = { "directory" })
@Test(groups = {"directory"})
public class MantaClientDirectoriesIT {

private static final Logger LOG = LoggerFactory.getLogger(MantaClientDirectoriesIT.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2017, Joyent, Inc. All rights reserved.
* Copyright (c) 2015-2019, Joyent, Inc. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -16,8 +16,6 @@
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import java.io.IOException;
Expand All @@ -31,10 +29,8 @@
/**
* Tests for verifying the correct behavior of error handling from Manta API
* failures.
*
* @author <a href="https://github.com/dekobon">Elijah Zupancic</a>
*/
@Test(groups = { "error" })
@Test(groups = {"error"})
public class MantaClientErrorIT {
private MantaClient mantaClient;

Expand All @@ -43,11 +39,9 @@ public class MantaClientErrorIT {
private String testPathPrefix;

@BeforeClass
@Parameters({"usingEncryption"})
public void beforeClass(@Optional Boolean usingEncryption) throws IOException {

public void beforeClass() throws IOException {
// Let TestNG configuration take precedence over environment variables
config = new IntegrationTestConfigContext(usingEncryption);
config = new IntegrationTestConfigContext();

mantaClient = new MantaClient(config);
testPathPrefix = IntegrationTestConfigContext.generateBasePathWithoutSeparator(config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,31 @@

/**
* Tests the basic functionality of the {@link MantaClient} class.
*
* @author <a href="https://github.com/yunong">Yunong Xiao</a>
* @author <a href="https://github.com/dekobon">Elijah Zupancic</a>
* @author <a href="https://github.com/nairashwin952013">Ashwin A Nair</a>
*/
@Test
@Test(groups = {"encrypted"})
public class MantaClientIT {

private static final String TEST_DATA = "EPISODEII_IS_BEST_EPISODE";

private MantaClient mantaClient;
private final MantaClient mantaClient;

private String testPathPrefix;
private final String testPathPrefix;

@BeforeClass
@Parameters({"usingEncryption", "testType"})
public void beforeClass(@Optional Boolean usingEncryption,
@Optional String testType) throws IOException {
@ Parameters({"encryptionCipher", "testType"})
public MantaClientIT(final @Optional String encryptionCipher) {

// Let TestNG configuration take precedence over environment variables
ConfigContext config = new IntegrationTestConfigContext(usingEncryption);

ConfigContext config = new IntegrationTestConfigContext(encryptionCipher);
String testName = this.getClass().getSimpleName();

mantaClient = new MantaClient(config);
testPathPrefix = IntegrationTestHelper.setupTestPath(config, mantaClient,
testName, testType);
}

@BeforeClass
public void beforeClass() throws IOException {
IntegrationTestHelper.createTestBucketOrDirectory(mantaClient, testPathPrefix, testType);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2017, Joyent, Inc. All rights reserved.
* Copyright (c) 2015-2019, Joyent, Inc. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -24,26 +24,27 @@

/**
* Tests for verifying the behavior of metadata with {@link MantaClient}.
*
* @author <a href="https://github.com/dekobon">Elijah Zupancic</a>
*/
@Test( groups = { "metadata" })
@Test(groups = {"metadata"})
public class MantaClientMetadataIT {
private static final String TEST_DATA = "EPISODEII_IS_BEST_EPISODE";

private MantaClient mantaClient;
private final MantaClient mantaClient;

private String testPathPrefix;
private final String testPathPrefix;

@BeforeClass
@Parameters({"usingEncryption"})
public void beforeClass(@Optional Boolean usingEncryption) throws IOException {
@Parameters({"encryptionCipher"})
public MantaClientMetadataIT(final @Optional String encryptionCipher) {

// Let TestNG configuration take precedence over environment variables
ConfigContext config = new IntegrationTestConfigContext(usingEncryption);
ConfigContext config = new IntegrationTestConfigContext(encryptionCipher);

mantaClient = new MantaClient(config);
testPathPrefix = IntegrationTestConfigContext.generateBasePath(config, this.getClass().getSimpleName());
}

@BeforeClass
public void beforeClass() throws IOException {
mantaClient.putDirectory(testPathPrefix, true);
}

Expand Down Expand Up @@ -148,7 +149,7 @@ public final void verifyCanRemoveMetadata() throws IOException, CloneNotSupporte
String.format("Actual metadata: %s", get.getMetadata()));
}

@Test(groups = { "metadata", "directory" })
@Test
public void canAddMetadataToDirectory() throws IOException {
String dir = String.format("%s%s", testPathPrefix, UUID.randomUUID());
mantaClient.putDirectory(dir);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2017, Joyent, Inc. All rights reserved.
* Copyright (c) 2016-2019, Joyent, Inc. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -41,7 +41,10 @@

import static com.joyent.manta.exception.MantaErrorCode.RESOURCE_NOT_FOUND_ERROR;

@Test
/**
* Tests the basic functionality of the put operations in {@link MantaClient} class.
*/
@Test(groups = {"put"})
public class MantaClientPutIT {

private static final String TEST_DATA = "EPISODEII_IS_BEST_EPISODE";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/*
* Copyright (c) 2017, Joyent, Inc. All rights reserved.
* Copyright (c) 2017-2019, Joyent, Inc. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.joyent.manta.client;

import com.joyent.manta.config.*;
import com.joyent.manta.config.BaseChainedConfigContext;
import com.joyent.manta.config.ConfigContext;
import com.joyent.manta.config.EncryptionAuthenticationMode;
import com.joyent.manta.config.IntegrationTestConfigContext;
import com.joyent.manta.config.SettableConfigContext;
import com.joyent.manta.http.MantaHttpHeaders;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -23,6 +27,10 @@
import java.nio.charset.Charset;
import java.util.UUID;

/**
* Tests for verifying the correct behavior of range operations performed by
* the {@link MantaClient} class.
*/
@Test
public class MantaClientRangeIT {
private static final String TEST_DATA =
Expand All @@ -49,23 +57,30 @@ public class MantaClientRangeIT {
"Girt with a seint* of silk, with barres small; " +
"Of his array tell I no longer tale.";

private MantaClient mantaClient;
private final MantaClient mantaClient;

private String testPathPrefix;
private final ConfigContext config;

@BeforeClass
@Parameters({"usingEncryption"})
public void beforeClass(@Optional Boolean usingEncryption) throws IOException {
// Let TestNG configuration take precedence over environment variables
SettableConfigContext<BaseChainedConfigContext> config = new IntegrationTestConfigContext(usingEncryption);
private final String testPathPrefix;

@Parameters({"encryptionCipher"})
public MantaClientRangeIT(final @Optional String encryptionCipher) {

// Let TestNG configuration take precedence over environment variables
SettableConfigContext<BaseChainedConfigContext> config = new IntegrationTestConfigContext(encryptionCipher);
// Range request have to be in optional authentication mode
if (config.isClientEncryptionEnabled()) {
config.setEncryptionAuthenticationMode(EncryptionAuthenticationMode.Optional);
}

mantaClient = new MantaClient(config);
this.config = config;
testPathPrefix = IntegrationTestConfigContext.generateBasePath(config, this.getClass().getSimpleName());

}

@BeforeClass
public void beforeClass() throws IOException {
mantaClient.putDirectory(testPathPrefix, true);
}

Expand Down
Loading

0 comments on commit 9b874b9

Please sign in to comment.