Skip to content

Commit

Permalink
Add support for .singleton (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler authored Oct 7, 2023
1 parent 277ee88 commit da375d7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
strategy:
matrix:
image:
- swift:5.6
- swift:5.7
- swift:5.8
- swift:5.9
services:
localstack:
image: localstack/localstack
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7
//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
Expand All @@ -22,7 +22,7 @@ let package = Package(
.library(name: "SotoS3FileTransfer", targets: ["SotoS3FileTransfer"]),
],
dependencies: [
.package(url: "https://github.com/soto-project/soto.git", from: "6.6.0"),
.package(url: "https://github.com/soto-project/soto.git", from: "6.8.0"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.0")
],
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Soto S3 Transfer uses the Soto Swift SDK for AWS. You need to create a Soto S3 s
```swift
let client = AWSClient(httpClientProvider: .createNew)
let s3 = S3(client: client, region: .euwest1)
let s3FileTransfer = S3FileTransferManager(s3: s3, threadPoolProvider: .createNew)
let s3FileTransfer = S3FileTransferManager(s3: s3, threadPoolProvider: .singleton)
```

## Shutdown
Expand All @@ -36,7 +36,7 @@ If you are uploading a folder multiple files will be uploaded in parallel. The n
```swift
let s3Transfer = S3FileTransferManager(
s3: s3,
threadPoolProvider: .createNew,
threadPoolProvider: .singleton,
configuration: .init(maxConcurrentTasks: 8)
)
```
Expand Down Expand Up @@ -91,7 +91,7 @@ If uploads are above a certain size then the transfer manager will use multipart
```swift
let s3Transfer = S3FileTransferManager(
s3: s3,
threadPoolProvider: .createNew,
threadPoolProvider: .singleton,
configuration: .init(multipartThreshold: 16*1024*1024, multipartPartSize: 16*1024*1024)
)
```
2 changes: 2 additions & 0 deletions Sources/SotoS3FileTransfer/S3FileTransferManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public class S3FileTransferManager {
case .createNew:
self.threadPool = NIOThreadPool(numberOfThreads: 2)
self.threadPool.start()
case .singleton:
self.threadPool = NIOThreadPool.singleton
case .shared(let sharedPool):
self.threadPool = sharedPool
}
Expand Down
10 changes: 5 additions & 5 deletions Tests/SotoS3FileTransferTests/S3FileTransferManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class S3TransferManagerXCTestCase: XCTestCase {
region: .euwest1,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
).with(timeout: .seconds(30))
self.s3FileTransfer = .init(s3: self.s3, threadPoolProvider: .createNew, logger: Logger(label: "S3TransferTests"))
self.s3FileTransfer = .init(s3: self.s3, threadPoolProvider: .singleton, logger: Logger(label: "S3TransferTests"))

XCTAssertNoThrow(try FileManager.default.createDirectory(atPath: self.tempFolder, withIntermediateDirectories: false))
XCTAssertNoThrow(try self.s3.createBucket(.init(bucket: self.bucketName)).wait())
Expand Down Expand Up @@ -99,7 +99,7 @@ class S3TransferManagerXCTestCase: XCTestCase {

final class S3FileTransferManagerTests: S3TransferManagerXCTestCase {
func testSyncShutdown() {
let s3FileTransfer = S3FileTransferManager(s3: Self.s3, threadPoolProvider: .createNew, logger: Logger(label: "S3TransferTests"))
let s3FileTransfer = S3FileTransferManager(s3: Self.s3, threadPoolProvider: .singleton, logger: Logger(label: "S3TransferTests"))
XCTAssertNoThrow(try s3FileTransfer.syncShutdown())
}

Expand Down Expand Up @@ -300,7 +300,7 @@ final class S3FileTransferManagerTests: S3TransferManagerXCTestCase {
func testCancelledSyncWithCancel() {
let s3FileTransfer = S3FileTransferManager(
s3: Self.s3,
threadPoolProvider: .createNew,
threadPoolProvider: .singleton,
configuration: .init(cancelOnError: true, maxConcurrentTasks: 2),
logger: Logger(label: "S3TransferTests")
)
Expand All @@ -314,7 +314,7 @@ final class S3FileTransferManagerTests: S3TransferManagerXCTestCase {
func testCancelledSyncWithFlush() {
let s3FileTransfer = S3FileTransferManager(
s3: Self.s3,
threadPoolProvider: .createNew,
threadPoolProvider: .singleton,
configuration: .init(cancelOnError: false, maxConcurrentTasks: 2),
logger: Logger(label: "S3TransferTests")
)
Expand Down Expand Up @@ -360,7 +360,7 @@ final class S3FileTransferManagerTests: S3TransferManagerXCTestCase {
func testCancelledDownloadWithCancel() {
let s3FileTransfer = S3FileTransferManager(
s3: Self.s3,
threadPoolProvider: .createNew,
threadPoolProvider: .singleton,
configuration: .init(cancelOnError: true, maxConcurrentTasks: 2),
logger: Logger(label: "S3TransferTests")
)
Expand Down

0 comments on commit da375d7

Please sign in to comment.