Skip to content

Commit 63d8024

Browse files
bullet-toothvkedia
authored andcommitted
---
yaml --- r: 8365 b: refs/heads/snehashah-snippets c: bebc2ef h: refs/heads/master i: 8363: 088ed29
1 parent 1f52d9a commit 63d8024

3 files changed

Lines changed: 79 additions & 10 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5656
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5757
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5858
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
59-
refs/heads/snehashah-snippets: be26690e2461ec271e16376a86afef64f3448b42
59+
refs/heads/snehashah-snippets: bebc2efedf0bb71c6a58fa043d02844f344824c8
6060
refs/tags/v0.20.2: 5a53aa06f268b74dc192204f4f83e1a04d40f65d
6161
refs/tags/v0.20.3: 269025fdc14af0b68df214a4518be5379b2fe569
6262
refs/tags/v0.21.0: f88b200e00e41ba6262ee88a92abba38b1e2417e

branches/snehashah-snippets/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPoolOptions.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ public static class Builder {
9090
* in parallel. Defaults to 0.
9191
*/
9292
public Builder setMinSessions(int minSessions) {
93-
Preconditions.checkArgument(
94-
maxSessions >= minSessions, "Min sessions must be <= max sessions");
9593
this.minSessions = minSessions;
9694
return this;
9795
}
@@ -103,8 +101,6 @@ public Builder setMinSessions(int minSessions) {
103101
* can either block or fail. Defaults to 2000.
104102
*/
105103
public Builder setMaxSessions(int maxSessions) {
106-
Preconditions.checkArgument(
107-
maxSessions >= minSessions, "Max sessions must be >= min" + "sessions");
108104
this.maxSessions = maxSessions;
109105
return this;
110106
}
@@ -127,8 +123,6 @@ public Builder setMaxIdleSessions(int maxIdleSessions) {
127123
* query "Select 1". Default value is 30 minutes.
128124
*/
129125
public Builder setKeepAliveIntervalMinutes(int intervalMinutes) {
130-
Preconditions.checkArgument(
131-
intervalMinutes < 60, "Keep alive interval should be less than" + "60 minutes");
132126
this.keepAliveIntervalMinutes = intervalMinutes;
133127
return this;
134128
}
@@ -161,16 +155,24 @@ public Builder setBlockIfPoolExhausted() {
161155
* <p>Default value is 0.2.
162156
*/
163157
public Builder setWriteSessionsFraction(float writeSessionsFraction) {
164-
Preconditions.checkArgument(
165-
writeSessionsFraction >= 0 && writeSessionsFraction <= 1,
166-
"Fraction of write sessions must be between 0 and 1 (inclusive)");
167158
this.writeSessionsFraction = writeSessionsFraction;
168159
return this;
169160
}
170161

171162
/** Build a SessionPoolOption object */
172163
public SessionPoolOptions build() {
164+
validate();
173165
return new SessionPoolOptions(this);
174166
}
167+
168+
private void validate() {
169+
Preconditions.checkArgument(maxSessions >= minSessions,
170+
"Min sessions(%s) must be <= max sessions(%s)", minSessions, maxSessions);
171+
Preconditions.checkArgument(
172+
keepAliveIntervalMinutes < 60, "Keep alive interval should be less than" + "60 minutes");
173+
Preconditions.checkArgument(
174+
writeSessionsFraction >= 0 && writeSessionsFraction <= 1,
175+
"Fraction of write sessions must be between 0 and 1 (inclusive)");
176+
}
175177
}
176178
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2017 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.spanner;
17+
18+
import org.junit.Rule;
19+
import org.junit.Test;
20+
import org.junit.rules.ExpectedException;
21+
import org.junit.runner.RunWith;
22+
import org.junit.runners.Parameterized;
23+
24+
import java.util.ArrayList;
25+
import java.util.Collection;
26+
import java.util.List;
27+
28+
import static junit.framework.TestCase.assertEquals;
29+
import static org.junit.runners.Parameterized.Parameter;
30+
import static org.junit.runners.Parameterized.Parameters;
31+
32+
/**
33+
* Unit tests for {@link com.google.cloud.spanner.SessionPoolOptions}
34+
*/
35+
@RunWith(Parameterized.class)
36+
public class SessionPoolOptionsTest {
37+
@Rule
38+
public ExpectedException expectedException = ExpectedException.none();
39+
@Parameter
40+
public int minSessions;
41+
@Parameter(1)
42+
public int maxSessions;
43+
44+
@Parameters(name = "min sessions = {0}, max sessions = {1}")
45+
public static Collection<Object[]> data() {
46+
List<Object[]> params = new ArrayList<>();
47+
params.add(new Object[]{1, 1});
48+
params.add(new Object[]{500, 600});
49+
params.add(new Object[]{600, 500});
50+
51+
return params;
52+
}
53+
54+
@Test
55+
public void setMinMaxSessions() {
56+
if (minSessions > maxSessions) {
57+
expectedException.expect(IllegalArgumentException.class);
58+
}
59+
SessionPoolOptions options = SessionPoolOptions.newBuilder()
60+
.setMinSessions(minSessions)
61+
.setMaxSessions(maxSessions)
62+
.build();
63+
64+
assertEquals(minSessions, options.getMinSessions());
65+
assertEquals(maxSessions, options.getMaxSessions());
66+
}
67+
}

0 commit comments

Comments
 (0)