Skip to content

Commit ba66cd3

Browse files
committed
Adapt integration tests to secure settings
1 parent cb78313 commit ba66cd3

3 files changed

Lines changed: 46 additions & 41 deletions

File tree

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AbstractAzureWithThirdPartyIntegTestCase.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@
1919

2020
package org.elasticsearch.repositories.azure;
2121

22+
import com.carrotsearch.randomizedtesting.RandomizedTest;
23+
import com.microsoft.azure.storage.LocationMode;
24+
import com.microsoft.azure.storage.StorageException;
25+
import org.elasticsearch.common.Strings;
2226
import org.elasticsearch.common.settings.Settings;
2327
import org.elasticsearch.plugins.Plugin;
2428
import org.elasticsearch.test.ESIntegTestCase.ThirdParty;
29+
import org.junit.After;
30+
import org.junit.Before;
2531

26-
import java.util.Arrays;
32+
import java.net.URISyntaxException;
2733
import java.util.Collection;
34+
import java.util.Collections;
35+
import java.util.Locale;
36+
import java.util.concurrent.TimeUnit;
2837

2938
import static org.elasticsearch.repositories.azure.AzureTestUtils.generateMockSecureSettings;
3039

@@ -41,6 +50,10 @@ Settings.Builder generateMockSettings() {
4150
return Settings.builder().setSecureSettings(generateMockSecureSettings());
4251
}
4352

53+
final AzureStorageService azureStorageService = new AzureStorageServiceImpl(generateMockSettings().build(),
54+
AzureStorageSettings.load(generateMockSettings().build()));
55+
final String containerName = getContainerName();
56+
4457
@Override
4558
protected Settings nodeSettings(int nodeOrdinal) {
4659
return generateMockSettings()
@@ -50,7 +63,38 @@ protected Settings nodeSettings(int nodeOrdinal) {
5063

5164
@Override
5265
protected Collection<Class<? extends Plugin>> nodePlugins() {
53-
return Arrays.asList(AzureRepositoryPlugin.class);
66+
return Collections.singletonList(AzureRepositoryPlugin.class);
67+
}
68+
69+
public static String getContainerName() {
70+
/* Have a different name per test so that there is no possible race condition. As the long can be negative,
71+
* there mustn't be a hyphen between the 2 concatenated numbers
72+
* (can't have 2 consecutives hyphens on Azure containers)
73+
*/
74+
String testName = "snapshot-itest-"
75+
.concat(RandomizedTest.getContext().getRunnerSeedAsString().toLowerCase(Locale.ROOT));
76+
return testName.contains(" ") ? Strings.split(testName, " ")[0] : testName;
5477
}
5578

79+
@Before
80+
public void createContainer() throws Exception {
81+
// It could happen that we run this test really close to a previous one
82+
// so we might need some time to be able to create the container
83+
assertBusy(() -> {
84+
try {
85+
azureStorageService.createContainer("default", LocationMode.PRIMARY_ONLY, getContainerName());
86+
} catch (URISyntaxException e) {
87+
// Incorrect URL. This should never happen.
88+
fail();
89+
} catch (StorageException e) {
90+
// It could happen. Let's wait for a while.
91+
fail();
92+
}
93+
}, 30, TimeUnit.SECONDS);
94+
}
95+
96+
@After
97+
public void removeContainer() throws Exception {
98+
azureStorageService.removeContainer("default", LocationMode.PRIMARY_ONLY, getContainerName());
99+
}
56100
}

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureSnapshotRestoreListSnapshotsTests.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@
5454
transportClientRatio = 0.0)
5555
public class AzureSnapshotRestoreListSnapshotsTests extends AbstractAzureWithThirdPartyIntegTestCase {
5656

57-
private final AzureStorageService azureStorageService = new AzureStorageServiceImpl(generateMockSettings().build(),
58-
AzureStorageSettings.load(generateMockSettings().build()));
59-
private final String containerName = getContainerName();
60-
61-
public AzureSnapshotRestoreListSnapshotsTests() {
62-
}
63-
6457
public void testList() throws Exception {
6558
Client client = client();
6659
logger.info("--> creating azure primary repository");
@@ -92,26 +85,4 @@ public void testList() throws Exception {
9285
logger.info("--> end of get snapshots on secondary. Took {} ms", endWait - startWait);
9386
assertThat(endWait - startWait, lessThanOrEqualTo(30000L));
9487
}
95-
96-
@Before
97-
public void createContainer() throws Exception {
98-
// It could happen that we run this test really close to a previous one
99-
// so we might need some time to be able to create the container
100-
assertBusy(() -> {
101-
try {
102-
azureStorageService.createContainer(null, LocationMode.PRIMARY_ONLY, containerName);
103-
} catch (URISyntaxException e) {
104-
// Incorrect URL. This should never happen.
105-
fail();
106-
} catch (StorageException e) {
107-
// It could happen. Let's wait for a while.
108-
fail();
109-
}
110-
}, 30, TimeUnit.SECONDS);
111-
}
112-
113-
@After
114-
public void removeContainer() throws Exception {
115-
azureStorageService.removeContainer(null, LocationMode.PRIMARY_ONLY, containerName);
116-
}
11788
}

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureSnapshotRestoreTests.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,6 @@ private String getRepositoryPath() {
7777
return testName.contains(" ") ? Strings.split(testName, " ")[0] : testName;
7878
}
7979

80-
public static String getContainerName() {
81-
/* Have a different name per test so that there is no possible race condition. As the long can be negative,
82-
* there mustn't be a hyphen between the 2 concatenated numbers
83-
* (can't have 2 consecutives hyphens on Azure containers)
84-
*/
85-
String testName = "snapshot-itest-"
86-
.concat(RandomizedTest.getContext().getRunnerSeedAsString().toLowerCase(Locale.ROOT));
87-
return testName.contains(" ") ? Strings.split(testName, " ")[0] : testName;
88-
}
89-
9080
@Override
9181
public Settings indexSettings() {
9282
// During restore we frequently restore index to exactly the same state it was before, that might cause the same

0 commit comments

Comments
 (0)