use of org.elasticsearch.Version in project elasticsearch by elastic.
the class Murmur3FieldMapperTests method testEmptyName.
public void testEmptyName() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("").field("type", "murmur3").endObject().endObject().endObject().endObject().string();
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> parser.parse("type", new CompressedXContent(mapping)));
assertThat(e.getMessage(), containsString("name cannot be empty string"));
// before 5.x
Version oldVersion = VersionUtils.randomVersionBetween(getRandom(), Version.V_2_0_0, Version.V_2_3_5);
Settings oldIndexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, oldVersion).build();
IndexService indexService2x = createIndex("test_old", oldIndexSettings);
Supplier<QueryShardContext> queryShardContext = () -> {
return indexService2x.newQueryShardContext(0, null, () -> {
throw new UnsupportedOperationException();
});
};
DocumentMapperParser parser = new DocumentMapperParser(indexService2x.getIndexSettings(), indexService2x.mapperService(), indexService2x.getIndexAnalyzers(), indexService2x.xContentRegistry(), indexService2x.similarityService(), mapperRegistry, queryShardContext);
DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, defaultMapper.mappingSource().string());
}
use of org.elasticsearch.Version in project elasticsearch by elastic.
the class ESClientYamlSuiteTestCase method readVersionsFromInfo.
private static Version readVersionsFromInfo(RestClient restClient, int numHosts) throws IOException {
Version version = null;
for (int i = 0; i < numHosts; i++) {
//we don't really use the urls here, we rely on the client doing round-robin to touch all the nodes in the cluster
Response response = restClient.performRequest("GET", "/");
ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response);
Object latestVersion = restTestResponse.evaluate("version.number");
if (latestVersion == null) {
throw new RuntimeException("elasticsearch version not found in the response");
}
final Version currentVersion = Version.fromString(latestVersion.toString());
if (version == null) {
version = currentVersion;
} else if (version.onOrAfter(currentVersion)) {
version = currentVersion;
}
}
return version;
}
use of org.elasticsearch.Version in project elasticsearch by elastic.
the class OldIndexUtils method getIndexDir.
public static Path getIndexDir(final Logger logger, final String indexName, final String indexFile, final Path dataDir) throws IOException {
final Version version = Version.fromString(indexName.substring("index-".length()));
if (version.before(Version.V_5_0_0_alpha1)) {
// the bwc scripts packs the indices under this path
Path src = dataDir.resolve("nodes/0/indices/" + indexName);
assertTrue("[" + indexFile + "] missing index dir: " + src.toString(), Files.exists(src));
return src;
} else {
final List<Path> indexFolders = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dataDir.resolve("0/indices"), (p) -> p.getFileName().toString().startsWith("extra") == false)) {
// extra FS can break this...
for (final Path path : stream) {
indexFolders.add(path);
}
}
assertThat(indexFolders.toString(), indexFolders.size(), equalTo(1));
final IndexMetaData indexMetaData = IndexMetaData.FORMAT.loadLatestState(logger, NamedXContentRegistry.EMPTY, indexFolders.get(0));
assertNotNull(indexMetaData);
assertThat(indexFolders.get(0).getFileName().toString(), equalTo(indexMetaData.getIndexUUID()));
assertThat(indexMetaData.getCreationVersion(), equalTo(version));
return indexFolders.get(0);
}
}
use of org.elasticsearch.Version in project elasticsearch by elastic.
the class AbstractQueryTestCase method beforeClass.
@BeforeClass
public static void beforeClass() {
// we have to prefer CURRENT since with the range of versions we support it's rather unlikely to get the current actually.
Version indexVersionCreated = randomBoolean() ? Version.CURRENT : VersionUtils.randomVersionBetween(random(), null, Version.CURRENT);
nodeSettings = Settings.builder().put("node.name", AbstractQueryTestCase.class.toString()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false).build();
indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, indexVersionCreated).build();
index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_");
//create some random type with some default field, those types will stick around for all of the subclasses
currentTypes = new String[randomIntBetween(0, 5)];
for (int i = 0; i < currentTypes.length; i++) {
String type = randomAsciiOfLengthBetween(1, 10);
currentTypes[i] = type;
}
//set some random types to be queried as part the search request, before each test
randomTypes = getRandomTypes();
}
use of org.elasticsearch.Version in project elasticsearch by elastic.
the class NodeTests method testWarnIfPreRelease.
public void testWarnIfPreRelease() {
final Logger logger = mock(Logger.class);
final int id = randomIntBetween(1, 9) * 1000000;
final Version releaseVersion = Version.fromId(id + 99);
final Version preReleaseVersion = Version.fromId(id + randomIntBetween(0, 98));
Node.warnIfPreRelease(releaseVersion, false, logger);
verifyNoMoreInteractions(logger);
reset(logger);
Node.warnIfPreRelease(releaseVersion, true, logger);
verify(logger).warn("version [{}] is a pre-release version of Elasticsearch and is not suitable for production", releaseVersion + "-SNAPSHOT");
reset(logger);
final boolean isSnapshot = randomBoolean();
Node.warnIfPreRelease(preReleaseVersion, isSnapshot, logger);
verify(logger).warn("version [{}] is a pre-release version of Elasticsearch and is not suitable for production", preReleaseVersion + (isSnapshot ? "-SNAPSHOT" : ""));
}
Aggregations