Skip to content

Commit 792220e

Browse files
author
andrey-qlogic
committed
4107: Added integration test testWriteChannelWithConnectionPool
1 parent 7e5820a commit 792220e

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

  • google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it

google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828
import static org.junit.Assume.assumeFalse;
2929
import static org.junit.Assume.assumeTrue;
3030

31+
import com.google.api.client.http.HttpTransport;
32+
import com.google.api.client.http.apache.ApacheHttpTransport;
3133
import com.google.api.client.util.DateTime;
3234
import com.google.api.gax.paging.Page;
3335
import com.google.auth.ServiceAccountSigner;
36+
import com.google.auth.http.HttpTransportFactory;
3437
import com.google.auth.oauth2.GoogleCredentials;
3538
import com.google.cloud.Identity;
3639
import com.google.cloud.Policy;
@@ -46,6 +49,8 @@
4649
import com.google.cloud.kms.v1.KeyManagementServiceGrpc;
4750
import com.google.cloud.kms.v1.KeyManagementServiceGrpc.KeyManagementServiceBlockingStub;
4851
import com.google.cloud.kms.v1.KeyRingName;
52+
import com.google.cloud.TransportOptions;
53+
import com.google.cloud.http.HttpTransportOptions;
4954
import com.google.cloud.kms.v1.LocationName;
5055
import com.google.cloud.storage.Acl;
5156
import com.google.cloud.storage.Acl.Role;
@@ -111,6 +116,8 @@
111116
import java.util.logging.Logger;
112117
import java.util.zip.GZIPInputStream;
113118
import javax.crypto.spec.SecretKeySpec;
119+
import org.apache.http.impl.client.HttpClients;
120+
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
114121
import org.junit.AfterClass;
115122
import org.junit.BeforeClass;
116123
import org.junit.Test;
@@ -184,6 +191,15 @@ public static void afterClass() throws ExecutionException, InterruptedException
184191
}
185192
}
186193

194+
private static class CustomHttpTransportFactory implements HttpTransportFactory {
195+
@Override
196+
public HttpTransport create() {
197+
PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager();
198+
manager.setMaxTotal(1);
199+
return new ApacheHttpTransport(HttpClients.createMinimal(manager));
200+
}
201+
}
202+
187203
private static void prepareKmsKeys() throws IOException {
188204
String projectId = remoteStorageHelper.getOptions().getProjectId();
189205
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault();
@@ -1744,6 +1760,27 @@ public void testWriteChannelExistingBlob() throws IOException {
17441760
assertTrue(storage.delete(BUCKET, blobName));
17451761
}
17461762

1763+
@Test(timeout = 5000)
1764+
public void testWriteChannelWithConnectionPool() throws IOException {
1765+
TransportOptions transportOptions = HttpTransportOptions.newBuilder()
1766+
.setHttpTransportFactory(new CustomHttpTransportFactory()).build();
1767+
Storage storageWithPool =
1768+
StorageOptions.newBuilder().setTransportOptions(transportOptions).build().getService();
1769+
String blobName = "test-read-and-write-channels-blob";
1770+
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
1771+
byte[] stringBytes;
1772+
try (WriteChannel writer = storageWithPool.writer(blob)) {
1773+
stringBytes = BLOB_STRING_CONTENT.getBytes(UTF_8);
1774+
writer.write(ByteBuffer.wrap(BLOB_BYTE_CONTENT));
1775+
writer.write(ByteBuffer.wrap(stringBytes));
1776+
}
1777+
try (WriteChannel writer = storageWithPool.writer(blob)) {
1778+
stringBytes = BLOB_STRING_CONTENT.getBytes(UTF_8);
1779+
writer.write(ByteBuffer.wrap(BLOB_BYTE_CONTENT));
1780+
writer.write(ByteBuffer.wrap(stringBytes));
1781+
}
1782+
}
1783+
17471784
@Test
17481785
public void testGetSignedUrl() throws IOException {
17491786
if (storage.getOptions().getCredentials() != null) {

0 commit comments

Comments
 (0)