Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move properties from atomix module to atomix-resource-manager. Remove standalone server example. properties -> options class naming. This reflects the idea that config can potentially (in the future) be populated by various sources, including properties files. Use Address host string constructor Move options to .options packages
- Loading branch information
1 parent
f18a105
commit 2afd569
Showing
25 changed files
with
760 additions
and
387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,62 @@ | |||
/* | |||
* Copyright 2015 the original author or authors. | |||
* | |||
* 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 | |||
*/ | |||
package io.atomix.config; | |||
|
|||
import java.util.Properties; | |||
|
|||
import io.atomix.Quorum; | |||
import io.atomix.manager.options.ServerOptions; | |||
|
|||
/** | |||
* Replica options. | |||
* | |||
* @author <a href="http://github.com/kuujo>Jordan Halterman</a> | |||
*/ | |||
public final class ReplicaOptions extends ServerOptions { | |||
public static final String QUORUM_HINT = "cluster.quorumHint"; | |||
public static final String BACKUP_COUNT = "cluster.backupCount"; | |||
|
|||
private static final int DEFAULT_QUORUM_HINT = -1; | |||
private static final int DEFAULT_BACKUP_COUNT = 0; | |||
|
|||
public ReplicaOptions(Properties properties) { | |||
super(properties); | |||
} | |||
|
|||
/** | |||
* Returns the quorum hint. | |||
* | |||
* @return The quorum hint. | |||
*/ | |||
public int quorumHint() { | |||
String quorumHint = reader.getString(QUORUM_HINT, String.valueOf(DEFAULT_QUORUM_HINT)); | |||
try { | |||
return Integer.valueOf(quorumHint); | |||
} catch (NumberFormatException e) { | |||
return Quorum.valueOf(quorumHint.trim().toUpperCase()).size(); | |||
} | |||
} | |||
|
|||
/** | |||
* Returns the backup count. | |||
* | |||
* @return The backup count. | |||
*/ | |||
public int backupCount() { | |||
return reader.getInteger(BACKUP_COUNT, DEFAULT_BACKUP_COUNT); | |||
} | |||
|
|||
} |
157 changes: 0 additions & 157 deletions
157
core/src/test/java/io/atomix/ReplicaPropertiesTest.java
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
core/src/test/java/io/atomix/config/ReplicaOptionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,67 @@ | |||
/* | |||
* Copyright 2016 the original author or authors. | |||
* | |||
* 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 | |||
*/ | |||
package io.atomix.config; | |||
|
|||
import static org.testng.Assert.assertEquals; | |||
|
|||
import java.util.Properties; | |||
|
|||
import org.testng.annotations.Test; | |||
|
|||
import io.atomix.catalyst.util.PropertiesReader; | |||
|
|||
/** | |||
* Replica options test. | |||
* | |||
* @author <a href="http://github.com/kuujo>Jordan Halterman</a> | |||
*/ | |||
@Test | |||
public class ReplicaOptionsTest { | |||
|
|||
/** | |||
* Tests default server properties. | |||
*/ | |||
public void testPropertyDefaults() { | |||
ReplicaOptions options = new ReplicaOptions(new Properties()); | |||
assertEquals(options.quorumHint(), -1); | |||
assertEquals(options.backupCount(), 0); | |||
} | |||
|
|||
/** | |||
* Tests reading properties. | |||
*/ | |||
public void testProperties() { | |||
Properties properties = new Properties(); | |||
properties.setProperty("cluster.quorumHint", "3"); | |||
properties.setProperty("cluster.backupCount", "1"); | |||
|
|||
ReplicaOptions options = new ReplicaOptions(properties); | |||
|
|||
assertEquals(options.quorumHint(), 3); | |||
assertEquals(options.backupCount(), 1); | |||
} | |||
|
|||
/** | |||
* Tests reading properties from a file. | |||
*/ | |||
public void testPropertiesFile() { | |||
ReplicaOptions options = new ReplicaOptions(PropertiesReader.loadFromClasspath("replica-test.properties").properties()); | |||
|
|||
assertEquals(options.quorumHint(), 3); | |||
assertEquals(options.backupCount(), 1); | |||
} | |||
|
|||
} |
Oops, something went wrong.