|
| 1 | +// |
| 2 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +// or more contributor license agreements. See the NOTICE file |
| 4 | +// distributed with this work for additional information |
| 5 | +// regarding copyright ownership. The ASF licenses this file |
| 6 | +// to you under the Apache License, Version 2.0 (the |
| 7 | +// "License"); you may not use this file except in compliance |
| 8 | +// with the License. You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, |
| 13 | +// software distributed under the License is distributed on an |
| 14 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +// KIND, either express or implied. See the License for the |
| 16 | +// specific language governing permissions and limitations |
| 17 | +// under the License. |
| 18 | +// |
| 19 | + |
| 20 | +import Foundation |
| 21 | +import Testing |
| 22 | + |
| 23 | +@testable import SparkConnect |
| 24 | + |
| 25 | +/// A test suite for `RuntimeConf` |
| 26 | +@Suite(.serialized) |
| 27 | +struct RuntimeConfTests { |
| 28 | + @Test |
| 29 | + func get() async throws { |
| 30 | + let client = SparkConnectClient(remote: "sc://localhost", user: "test") |
| 31 | + _ = try await client.connect(UUID().uuidString) |
| 32 | + let conf = RuntimeConf(client) |
| 33 | + |
| 34 | + #expect(try await conf.get("spark.app.name") == "Spark Connect server") |
| 35 | + |
| 36 | + try await #require(throws: Error.self) { |
| 37 | + try await conf.get("spark.test.non-exist") |
| 38 | + } |
| 39 | + |
| 40 | + await client.stop() |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + func set() async throws { |
| 45 | + let client = SparkConnectClient(remote: "sc://localhost", user: "test") |
| 46 | + _ = try await client.connect(UUID().uuidString) |
| 47 | + let conf = RuntimeConf(client) |
| 48 | + try await conf.set("spark.test.key1", "value1") |
| 49 | + #expect(try await conf.get("spark.test.key1") == "value1") |
| 50 | + await client.stop() |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + func reset() async throws { |
| 55 | + let client = SparkConnectClient(remote: "sc://localhost", user: "test") |
| 56 | + _ = try await client.connect(UUID().uuidString) |
| 57 | + let conf = RuntimeConf(client) |
| 58 | + |
| 59 | + // Success with a key that doesn't exist |
| 60 | + try await conf.unset("spark.test.key1") |
| 61 | + |
| 62 | + // Make it sure that `spark.test.key1` exists before testing `reset`. |
| 63 | + try await conf.set("spark.test.key1", "value1") |
| 64 | + #expect(try await conf.get("spark.test.key1") == "value1") |
| 65 | + |
| 66 | + try await conf.unset("spark.test.key1") |
| 67 | + try await #require(throws: Error.self) { |
| 68 | + try await conf.get("spark.test.key1") |
| 69 | + } |
| 70 | + |
| 71 | + await client.stop() |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + func getAll() async throws { |
| 76 | + let client = SparkConnectClient(remote: "sc://localhost", user: "test") |
| 77 | + _ = try await client.connect(UUID().uuidString) |
| 78 | + let conf = RuntimeConf(client) |
| 79 | + let map = try await conf.getAll() |
| 80 | + #expect(map.count > 0) |
| 81 | + #expect(map["spark.app.id"] != nil) |
| 82 | + #expect(map["spark.app.startTime"] != nil) |
| 83 | + #expect(map["spark.executor.id"] == "driver") |
| 84 | + #expect(map["spark.master"] != nil) |
| 85 | + await client.stop() |
| 86 | + } |
| 87 | +} |
0 commit comments