use of org.opensearch.common.settings.Settings.Builder in project OpenSearch by opensearch-project.
the class ElectionSchedulerFactoryTests method testRetriesOnCorrectSchedule.
public void testRetriesOnCorrectSchedule() {
final Builder settingsBuilder = Settings.builder();
final long initialTimeoutMillis;
if (randomBoolean()) {
initialTimeoutMillis = randomLongBetween(1, 10000);
settingsBuilder.put(ELECTION_INITIAL_TIMEOUT_SETTING.getKey(), initialTimeoutMillis + "ms");
} else {
initialTimeoutMillis = ELECTION_INITIAL_TIMEOUT_SETTING.get(Settings.EMPTY).millis();
}
if (randomBoolean()) {
settingsBuilder.put(ELECTION_BACK_OFF_TIME_SETTING.getKey(), randomLongBetween(1, 60000) + "ms");
}
if (ELECTION_MAX_TIMEOUT_SETTING.get(Settings.EMPTY).millis() < initialTimeoutMillis || randomBoolean()) {
settingsBuilder.put(ELECTION_MAX_TIMEOUT_SETTING.getKey(), randomLongBetween(Math.max(200, initialTimeoutMillis), 180000) + "ms");
}
final long electionDurationMillis;
if (randomBoolean()) {
electionDurationMillis = randomLongBetween(1, 300000);
settingsBuilder.put(ELECTION_DURATION_SETTING.getKey(), electionDurationMillis + "ms");
} else {
electionDurationMillis = ELECTION_DURATION_SETTING.get(Settings.EMPTY).millis();
}
final Settings settings = settingsBuilder.put(NODE_NAME_SETTING.getKey(), "node").build();
final long initialTimeout = ELECTION_INITIAL_TIMEOUT_SETTING.get(settings).millis();
final long backOffTime = ELECTION_BACK_OFF_TIME_SETTING.get(settings).millis();
final long maxTimeout = ELECTION_MAX_TIMEOUT_SETTING.get(settings).millis();
final long duration = ELECTION_DURATION_SETTING.get(settings).millis();
final DeterministicTaskQueue deterministicTaskQueue = new DeterministicTaskQueue(settings, random());
final ElectionSchedulerFactory electionSchedulerFactory = new ElectionSchedulerFactory(settings, random(), deterministicTaskQueue.getThreadPool());
assertElectionSchedule(deterministicTaskQueue, electionSchedulerFactory, initialTimeout, backOffTime, maxTimeout, duration);
// do it again to show that the max is reset when the scheduler is restarted
assertElectionSchedule(deterministicTaskQueue, electionSchedulerFactory, initialTimeout, backOffTime, maxTimeout, duration);
}
use of org.opensearch.common.settings.Settings.Builder in project OpenSearch by opensearch-project.
the class FollowersCheckerTests method testPreferClusterManagerNodes.
public void testPreferClusterManagerNodes() {
List<DiscoveryNode> nodes = randomNodes(10);
DiscoveryNodes.Builder discoNodesBuilder = DiscoveryNodes.builder();
nodes.forEach(dn -> discoNodesBuilder.add(dn));
DiscoveryNodes discoveryNodes = discoNodesBuilder.localNodeId(nodes.get(0).getId()).build();
CapturingTransport capturingTransport = new CapturingTransport();
final Settings settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), nodes.get(0).getName()).build();
final DeterministicTaskQueue deterministicTaskQueue = new DeterministicTaskQueue(settings, random());
TransportService transportService = capturingTransport.createTransportService(Settings.EMPTY, deterministicTaskQueue.getThreadPool(), TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> nodes.get(0), null, emptySet());
final FollowersChecker followersChecker = new FollowersChecker(Settings.EMPTY, transportService, fcr -> {
assert false : fcr;
}, (node, reason) -> {
assert false : node;
}, () -> new StatusInfo(HEALTHY, "healthy-info"));
followersChecker.setCurrentNodes(discoveryNodes);
List<DiscoveryNode> followerTargets = Stream.of(capturingTransport.getCapturedRequestsAndClear()).map(cr -> cr.node).collect(Collectors.toList());
List<DiscoveryNode> sortedFollowerTargets = new ArrayList<>(followerTargets);
Collections.sort(sortedFollowerTargets, Comparator.comparing(n -> n.isMasterNode() == false));
assertEquals(sortedFollowerTargets, followerTargets);
}
use of org.opensearch.common.settings.Settings.Builder in project security by opensearch-project.
the class DisabledCategoriesTest method invalidRestCategoryConfigurationTest.
@Test
public void invalidRestCategoryConfigurationTest() {
thrown.expect(IllegalArgumentException.class);
Builder settingsBuilder = Settings.builder();
settingsBuilder.put("plugins.security.audit.type", TestAuditlogImpl.class.getName());
settingsBuilder.put(ConfigConstants.OPENDISTRO_SECURITY_AUDIT_CONFIG_DISABLED_REST_CATEGORIES, "nonexistent");
AuditTestUtils.createAuditLog(settingsBuilder.build(), null, null, AbstractSecurityUnitTest.MOCK_POOL, null, cs);
}
use of org.opensearch.common.settings.Settings.Builder in project security by opensearch-project.
the class DisabledCategoriesTest method checkCategoriesDisabled.
/*@After
public void restoreOut() {
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
}*/
protected void checkCategoriesDisabled(AuditCategory... disabledCategories) throws Exception {
List<String> categoryNames = new LinkedList<>();
for (AuditCategory category : disabledCategories) {
categoryNames.add(category.name().toLowerCase());
}
String disabledCategoriesString = Joiner.on(",").join(categoryNames);
Builder settingsBuilder = Settings.builder();
settingsBuilder.put("plugins.security.audit.type", TestAuditlogImpl.class.getName());
settingsBuilder.put(ConfigConstants.OPENDISTRO_SECURITY_AUDIT_CONFIG_DISABLED_TRANSPORT_CATEGORIES, disabledCategoriesString);
settingsBuilder.put(ConfigConstants.OPENDISTRO_SECURITY_AUDIT_CONFIG_DISABLED_REST_CATEGORIES, disabledCategoriesString);
// we use the debug output, no OpenSearch client is needed. Also, we
// do not need to close.
AbstractAuditLog auditLog = AuditTestUtils.createAuditLog(settingsBuilder.build(), null, null, AbstractSecurityUnitTest.MOCK_POOL, null, cs);
logAll(auditLog);
auditLog.close();
String result = TestAuditlogImpl.sb.toString();
List<AuditCategory> allButDisablesCategories = new LinkedList<>(Arrays.asList(AuditCategory.values()));
allButDisablesCategories.removeAll(Arrays.asList(disabledCategories));
System.out.println(result + "###" + disabledCategoriesString);
Assert.assertFalse(categoriesPresentInLog(result, disabledCategories));
Assert.assertTrue(categoriesPresentInLog(result, filterComplianceCategories(allButDisablesCategories.toArray(new AuditCategory[] {}))));
}
use of org.opensearch.common.settings.Settings.Builder in project OpenSearch by opensearch-project.
the class StopTokenFilterTests method testPositionIncrementSetting.
public void testPositionIncrementSetting() throws IOException {
Builder builder = Settings.builder().put("index.analysis.filter.my_stop.type", "stop").put("index.analysis.filter.my_stop.enable_position_increments", false);
if (random().nextBoolean()) {
builder.put("index.analysis.filter.my_stop.version", "5.0");
}
builder.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString());
Settings settings = builder.build();
try {
AnalysisTestsHelper.createTestAnalysisFromSettings(settings);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("enable_position_increments is not supported anymore"));
}
}
Aggregations