3636import java .util .Locale ;
3737import java .util .UUID ;
3838
39+ import static org .elasticsearch .repositories .blobstore .BlobStoreTestUtil .randomPurpose ;
3940import static org .elasticsearch .xcontent .XContentFactory .jsonBuilder ;
4041import static org .hamcrest .Matchers .containsString ;
4142import 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