Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Y
YCSB
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Adnan Ahmad
YCSB
Commits
eaebc719
Commit
eaebc719
authored
9 years ago
by
Robert J. Moore
Browse files
Options
Downloads
Patches
Plain Diff
Tests and updates for OptionsSupport.
parent
d5626110
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mongodb/src/main/java/com/yahoo/ycsb/db/OptionsSupport.java
+14
-9
14 additions, 9 deletions
mongodb/src/main/java/com/yahoo/ycsb/db/OptionsSupport.java
mongodb/src/test/java/com/yahoo/ycsb/db/OptionsSupportTest.java
+189
-0
189 additions, 0 deletions
...b/src/test/java/com/yahoo/ycsb/db/OptionsSupportTest.java
with
203 additions
and
9 deletions
mongodb/src/main/java/com/yahoo/ycsb/db/OptionsSupport.java
+
14
−
9
View file @
eaebc719
...
...
@@ -24,9 +24,14 @@ import java.util.Properties;
/**
* OptionsSupport provides methods for handling legacy options.
*
* @author rjm
*/
public
final
class
OptionsSupport
{
/** Value for an unavailable property. */
protected
static
final
String
UNAVAILABLE
=
"n/a"
;
/**
* Updates the URL with the appropriate attributes if legacy properties are
* set and the URL does not have the property already set.
...
...
@@ -42,8 +47,8 @@ public final class OptionsSupport {
// max connections.
final
String
maxConnections
=
props
.
getProperty
(
"mongodb.maxconnections"
,
"N/A"
);
if
(!
"N/A"
.
equals
(
maxConnections
))
{
"mongodb.maxconnections"
,
UNAVAILABLE
).
toLowerCase
(
);
if
(!
UNAVAILABLE
.
equals
(
maxConnections
))
{
result
=
addUrlOption
(
result
,
"maxPoolSize"
,
maxConnections
);
}
...
...
@@ -51,16 +56,16 @@ public final class OptionsSupport {
final
String
threadsAllowedToBlockForConnectionMultiplier
=
props
.
getProperty
(
"mongodb.threadsAllowedToBlockForConnectionMultiplier"
,
"N/A"
);
if
(!
"N/A"
.
equals
(
threadsAllowedToBlockForConnectionMultiplier
))
{
UNAVAILABLE
).
toLowerCase
(
);
if
(!
UNAVAILABLE
.
equals
(
threadsAllowedToBlockForConnectionMultiplier
))
{
result
=
addUrlOption
(
result
,
"waitQueueMultiple"
,
threadsAllowedToBlockForConnectionMultiplier
);
}
// write concern
String
writeConcernType
=
props
.
getProperty
(
"mongodb.writeConcern"
,
"N/A"
).
toLowerCase
();
if
(!
"N/A"
.
equals
(
writeConcernType
))
{
UNAVAILABLE
).
toLowerCase
();
if
(!
UNAVAILABLE
.
equals
(
writeConcernType
))
{
if
(
"errors_ignored"
.
equals
(
writeConcernType
))
{
result
=
addUrlOption
(
result
,
"w"
,
"0"
);
}
...
...
@@ -83,9 +88,9 @@ public final class OptionsSupport {
}
// read preference
String
readPreferenceType
=
props
.
getProperty
(
"mongodb.
writeConcern
"
,
"N/A"
).
toLowerCase
();
if
(!
"N/A"
.
equals
(
readPreferenceType
))
{
String
readPreferenceType
=
props
.
getProperty
(
"mongodb.
readPreference
"
,
UNAVAILABLE
).
toLowerCase
();
if
(!
UNAVAILABLE
.
equals
(
readPreferenceType
))
{
if
(
"primary"
.
equals
(
readPreferenceType
))
{
result
=
addUrlOption
(
result
,
"readPreference"
,
"primary"
);
}
...
...
This diff is collapsed.
Click to expand it.
mongodb/src/test/java/com/yahoo/ycsb/db/OptionsSupportTest.java
0 → 100644
+
189
−
0
View file @
eaebc719
/*
* #%L
* OptionsSupport.java - mongodb-binding - Yahoo!, Inc.
* %%
* Copyright (C) 2015 Yahoo!, Inc.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package
com.yahoo.ycsb.db
;
import
static
com
.
yahoo
.
ycsb
.
db
.
OptionsSupport
.
updateUrl
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.util.Properties
;
import
org.junit.Test
;
/**
* OptionsSupportTest provides tests for the OptionsSupport class.
*
* @author rjm
*/
public
class
OptionsSupportTest
{
/**
* Test method for {@link OptionsSupport#updateUrl(String, Properties)} for
* {@code mongodb.maxconnections}.
*/
@Test
public
void
testUpdateUrlMaxConnections
()
{
assertThat
(
updateUrl
(
"mongodb://locahost:27017/"
,
props
(
"mongodb.maxconnections"
,
"1234"
)),
is
(
"mongodb://locahost:27017/?maxPoolSize=1234"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"mongodb.maxconnections"
,
"1234"
)),
is
(
"mongodb://locahost:27017/?foo=bar&maxPoolSize=1234"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?maxPoolSize=1"
,
props
(
"mongodb.maxconnections"
,
"1234"
)),
is
(
"mongodb://locahost:27017/?maxPoolSize=1"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"foo"
,
"1234"
)),
is
(
"mongodb://locahost:27017/?foo=bar"
));
}
/**
* Test method for {@link OptionsSupport#updateUrl(String, Properties)} for
* {@code mongodb.threadsAllowedToBlockForConnectionMultiplier}.
*/
@Test
public
void
testUpdateUrlWaitQueueMultiple
()
{
assertThat
(
updateUrl
(
"mongodb://locahost:27017/"
,
props
(
"mongodb.threadsAllowedToBlockForConnectionMultiplier"
,
"1234"
)),
is
(
"mongodb://locahost:27017/?waitQueueMultiple=1234"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"mongodb.threadsAllowedToBlockForConnectionMultiplier"
,
"1234"
)),
is
(
"mongodb://locahost:27017/?foo=bar&waitQueueMultiple=1234"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?waitQueueMultiple=1"
,
props
(
"mongodb.threadsAllowedToBlockForConnectionMultiplier"
,
"1234"
)),
is
(
"mongodb://locahost:27017/?waitQueueMultiple=1"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"foo"
,
"1234"
)),
is
(
"mongodb://locahost:27017/?foo=bar"
));
}
/**
* Test method for {@link OptionsSupport#updateUrl(String, Properties)} for
* {@code mongodb.threadsAllowedToBlockForConnectionMultiplier}.
*/
@Test
public
void
testUpdateUrlWriteConcern
()
{
assertThat
(
updateUrl
(
"mongodb://locahost:27017/"
,
props
(
"mongodb.writeConcern"
,
"errors_ignored"
)),
is
(
"mongodb://locahost:27017/?w=0"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"mongodb.writeConcern"
,
"unacknowledged"
)),
is
(
"mongodb://locahost:27017/?foo=bar&w=0"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"mongodb.writeConcern"
,
"acknowledged"
)),
is
(
"mongodb://locahost:27017/?foo=bar&w=1"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"mongodb.writeConcern"
,
"journaled"
)),
is
(
"mongodb://locahost:27017/?foo=bar&journal=true"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"mongodb.writeConcern"
,
"replica_acknowledged"
)),
is
(
"mongodb://locahost:27017/?foo=bar&w=2"
));
// w already exists.
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?w=1"
,
props
(
"mongodb.writeConcern"
,
"acknowledged"
)),
is
(
"mongodb://locahost:27017/?w=1"
));
// Unknown options
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"foo"
,
"1234"
)),
is
(
"mongodb://locahost:27017/?foo=bar"
));
}
/**
* Test method for {@link OptionsSupport#updateUrl(String, Properties)} for
* {@code mongodb.threadsAllowedToBlockForConnectionMultiplier}.
*/
@Test
public
void
testUpdateUrlReadPreference
()
{
assertThat
(
updateUrl
(
"mongodb://locahost:27017/"
,
props
(
"mongodb.readPreference"
,
"primary"
)),
is
(
"mongodb://locahost:27017/?readPreference=primary"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"mongodb.readPreference"
,
"primary_preferred"
)),
is
(
"mongodb://locahost:27017/?foo=bar&readPreference=primaryPreferred"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"mongodb.readPreference"
,
"secondary"
)),
is
(
"mongodb://locahost:27017/?foo=bar&readPreference=secondary"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"mongodb.readPreference"
,
"secondary_preferred"
)),
is
(
"mongodb://locahost:27017/?foo=bar&readPreference=secondaryPreferred"
));
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"mongodb.readPreference"
,
"nearest"
)),
is
(
"mongodb://locahost:27017/?foo=bar&readPreference=nearest"
));
// readPreference already exists.
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?readPreference=primary"
,
props
(
"mongodb.readPreference"
,
"secondary"
)),
is
(
"mongodb://locahost:27017/?readPreference=primary"
));
// Unknown options
assertThat
(
updateUrl
(
"mongodb://locahost:27017/?foo=bar"
,
props
(
"foo"
,
"1234"
)),
is
(
"mongodb://locahost:27017/?foo=bar"
));
}
/**
* Factory method for a {@link Properties} object.
*
* @param key
* The key for the property to set.
* @param value
* The value for the property to set.
* @return The {@link Properties} with the property added.
*/
private
Properties
props
(
String
key
,
String
value
)
{
Properties
props
=
new
Properties
();
props
.
setProperty
(
key
,
value
);
return
props
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment