Skip to content

Commit 98c4751

Browse files
committed
Fix tests
1 parent 49c5640 commit 98c4751

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

modules/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreContainerTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.common.blobstore.BlobContainer;
2222
import org.elasticsearch.common.blobstore.BlobPath;
2323
import org.elasticsearch.common.blobstore.BlobStore;
24+
import org.elasticsearch.common.blobstore.OperationPurpose;
2425
import org.elasticsearch.common.util.BigArrays;
2526
import org.elasticsearch.test.ESTestCase;
2627

@@ -79,7 +80,14 @@ public void testDeleteBlobsIgnoringIfNotExistsThrowsIOException() throws Excepti
7980
when(storage.batch()).thenReturn(batch);
8081

8182
final GoogleCloudStorageService storageService = mock(GoogleCloudStorageService.class);
82-
when(storageService.client(any(String.class), any(String.class), any(GoogleCloudStorageOperationsStats.class))).thenReturn(storage);
83+
when(
84+
storageService.client(
85+
any(String.class),
86+
any(String.class),
87+
any(OperationPurpose.class),
88+
any(GoogleCloudStorageOperationsStats.class)
89+
)
90+
).thenReturn(storage);
8391

8492
try (
8593
BlobStore store = new GoogleCloudStorageBlobStore(

modules/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageServiceTests.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Locale;
3737
import java.util.UUID;
3838

39+
import static org.elasticsearch.repositories.blobstore.BlobStoreTestUtil.randomPurpose;
3940
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
4041
import static org.hamcrest.Matchers.containsString;
4142
import static org.hamcrest.Matchers.equalTo;
@@ -82,13 +83,13 @@ void notifyProxyIsSet(Proxy p) {
8283
GoogleCloudStorageOperationsStats statsCollector = new GoogleCloudStorageOperationsStats("bucket");
8384
final IllegalArgumentException e = expectThrows(
8485
IllegalArgumentException.class,
85-
() -> service.client("another_client", "repo", statsCollector)
86+
() -> service.client("another_client", "repo", randomPurpose(), statsCollector)
8687
);
8788
assertThat(e.getMessage(), Matchers.startsWith("Unknown client name"));
8889
assertSettingDeprecationsAndWarnings(
8990
new Setting<?>[] { GoogleCloudStorageClientSettings.APPLICATION_NAME_SETTING.getConcreteSettingForNamespace(clientName) }
9091
);
91-
final Storage storage = service.client(clientName, "repo", statsCollector);
92+
final Storage storage = service.client(clientName, "repo", randomPurpose(), statsCollector);
9293
assertThat(storage.getOptions().getApplicationName(), Matchers.containsString(applicationName));
9394
assertThat(storage.getOptions().getHost(), Matchers.is(endpoint));
9495
assertThat(storage.getOptions().getProjectId(), Matchers.is(projectIdName));
@@ -116,33 +117,33 @@ public void testReinitClientSettings() throws Exception {
116117
try (GoogleCloudStoragePlugin plugin = new GoogleCloudStoragePlugin(settings1)) {
117118
final GoogleCloudStorageService storageService = plugin.storageService;
118119
GoogleCloudStorageOperationsStats statsCollector = new GoogleCloudStorageOperationsStats("bucket");
119-
final Storage client11 = storageService.client("gcs1", "repo1", statsCollector);
120+
final Storage client11 = storageService.client("gcs1", "repo1", randomPurpose(), statsCollector);
120121
assertThat(client11.getOptions().getProjectId(), equalTo("project_gcs11"));
121-
final Storage client12 = storageService.client("gcs2", "repo2", statsCollector);
122+
final Storage client12 = storageService.client("gcs2", "repo2", randomPurpose(), statsCollector);
122123
assertThat(client12.getOptions().getProjectId(), equalTo("project_gcs12"));
123124
// client 3 is missing
124125
final IllegalArgumentException e1 = expectThrows(
125126
IllegalArgumentException.class,
126-
() -> storageService.client("gcs3", "repo3", statsCollector)
127+
() -> storageService.client("gcs3", "repo3", randomPurpose(), statsCollector)
127128
);
128129
assertThat(e1.getMessage(), containsString("Unknown client name [gcs3]."));
129130
// update client settings
130131
plugin.reload(settings2);
131132
// old client 1 not changed
132133
assertThat(client11.getOptions().getProjectId(), equalTo("project_gcs11"));
133134
// new client 1 is changed
134-
final Storage client21 = storageService.client("gcs1", "repo1", statsCollector);
135+
final Storage client21 = storageService.client("gcs1", "repo1", randomPurpose(), statsCollector);
135136
assertThat(client21.getOptions().getProjectId(), equalTo("project_gcs21"));
136137
// old client 2 not changed
137138
assertThat(client12.getOptions().getProjectId(), equalTo("project_gcs12"));
138139
// new client2 is gone
139140
final IllegalArgumentException e2 = expectThrows(
140141
IllegalArgumentException.class,
141-
() -> storageService.client("gcs2", "repo2", statsCollector)
142+
() -> storageService.client("gcs2", "repo2", randomPurpose(), statsCollector)
142143
);
143144
assertThat(e2.getMessage(), containsString("Unknown client name [gcs2]."));
144145
// client 3 emerged
145-
final Storage client23 = storageService.client("gcs3", "repo3", statsCollector);
146+
final Storage client23 = storageService.client("gcs3", "repo3", randomPurpose(), statsCollector);
146147
assertThat(client23.getOptions().getProjectId(), equalTo("project_gcs23"));
147148
}
148149
}
@@ -154,11 +155,22 @@ public void testClientsAreNotSharedAcrossRepositories() throws Exception {
154155
try (GoogleCloudStoragePlugin plugin = new GoogleCloudStoragePlugin(settings)) {
155156
final GoogleCloudStorageService storageService = plugin.storageService;
156157

157-
final Storage repo1Client = storageService.client("gcs1", "repo1", new GoogleCloudStorageOperationsStats("bucket"));
158-
final Storage repo2Client = storageService.client("gcs1", "repo2", new GoogleCloudStorageOperationsStats("bucket"));
158+
final Storage repo1Client = storageService.client(
159+
"gcs1",
160+
"repo1",
161+
randomPurpose(),
162+
new GoogleCloudStorageOperationsStats("bucket")
163+
);
164+
final Storage repo2Client = storageService.client(
165+
"gcs1",
166+
"repo2",
167+
randomPurpose(),
168+
new GoogleCloudStorageOperationsStats("bucket")
169+
);
159170
final Storage repo1ClientSecondInstance = storageService.client(
160171
"gcs1",
161172
"repo1",
173+
randomPurpose(),
162174
new GoogleCloudStorageOperationsStats("bucket")
163175
);
164176

0 commit comments

Comments
 (0)