use of org.elasticsearch.cli.UserException in project elasticsearch by elastic.
the class EvilLoggerConfigurationTests method testMissingConfigFile.
public void testMissingConfigFile() {
final Path configDir = getDataPath("does_not_exist");
final Settings settings = Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), configDir.toAbsolutePath()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
final Environment environment = new Environment(settings);
UserException e = expectThrows(UserException.class, () -> LogConfigurator.configure(environment));
assertThat(e, hasToString(containsString("no log4j2.properties found; tried")));
}
use of org.elasticsearch.cli.UserException in project elasticsearch by elastic.
the class EvilLoggerTests method testPrefixLogger.
public void testPrefixLogger() throws IOException, IllegalAccessException, UserException {
setupLogging("prefix");
final String prefix = randomBoolean() ? null : randomAsciiOfLength(16);
final Logger logger = Loggers.getLogger("prefix", prefix);
logger.info("test");
logger.info("{}", "test");
final Exception e = new Exception("exception");
logger.info(new ParameterizedMessage("{}", "test"), e);
final String path = System.getProperty("es.logs.base_path") + System.getProperty("file.separator") + System.getProperty("es.logs.cluster_name") + ".log";
final List<String> events = Files.readAllLines(PathUtils.get(path));
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
final int stackTraceLength = sw.toString().split(System.getProperty("line.separator")).length;
final int expectedLogLines = 3;
assertThat(events.size(), equalTo(expectedLogLines + stackTraceLength));
for (int i = 0; i < expectedLogLines; i++) {
if (prefix == null) {
assertThat(events.get(i), startsWith("test"));
} else {
assertThat(events.get(i), startsWith("[" + prefix + "] test"));
}
}
}
use of org.elasticsearch.cli.UserException in project elasticsearch by elastic.
the class InstallPluginCommandTests method testConfigNotDir.
public void testConfigNotDir() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
Path pluginDir = createPluginDir(temp);
Path configDir = pluginDir.resolve("config");
Files.createFile(configDir);
String pluginZip = createPlugin("fake", pluginDir);
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
assertTrue(e.getMessage(), e.getMessage().contains("not a directory"));
assertInstallCleaned(env.v2());
}
use of org.elasticsearch.cli.UserException in project elasticsearch by elastic.
the class InstallPluginCommandTests method testConfigContainsDir.
public void testConfigContainsDir() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
Path pluginDir = createPluginDir(temp);
Path dirInConfigDir = pluginDir.resolve("config").resolve("foo");
Files.createDirectories(dirInConfigDir);
Files.createFile(dirInConfigDir.resolve("myconfig.yml"));
String pluginZip = createPlugin("fake", pluginDir);
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
assertTrue(e.getMessage(), e.getMessage().contains("Directories not allowed in config dir for plugin"));
assertInstallCleaned(env.v2());
}
use of org.elasticsearch.cli.UserException in project elasticsearch by elastic.
the class InstallPluginCommandTests method testExistingPlugin.
public void testExistingPlugin() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
Path pluginDir = createPluginDir(temp);
String pluginZip = createPlugin("fake", pluginDir);
installPlugin(pluginZip, env.v1());
UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
assertTrue(e.getMessage(), e.getMessage().contains("already exists"));
assertInstallCleaned(env.v2());
}
Aggregations