use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions in project elasticsearch by elastic.
the class AliasActionsTests method testEmptyIndex.
public void testEmptyIndex() {
Exception e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(randomFrom(AliasActions.Type.values())).index(null));
assertEquals("[index] can't be empty string", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(randomFrom(AliasActions.Type.values())).index(""));
assertEquals("[index] can't be empty string", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(randomFrom(AliasActions.Type.values())).indices((String[]) null));
assertEquals("[indices] can't be empty", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(randomFrom(AliasActions.Type.values())).indices(new String[0]));
assertEquals("[indices] can't be empty", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(randomFrom(AliasActions.Type.values())).indices("test", null));
assertEquals("[indices] can't contain empty string", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(randomFrom(AliasActions.Type.values())).indices("test", ""));
assertEquals("[indices] can't contain empty string", e.getMessage());
}
use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions in project elasticsearch by elastic.
the class AliasActionsTests method testParseRemoveIndex.
public void testParseRemoveIndex() throws IOException {
String[] indices = randomBoolean() ? new String[] { randomAsciiOfLength(5) } : generateRandomStringArray(10, 5, false, false);
XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
b.startObject();
{
b.startObject("remove_index");
{
if (indices.length > 1 || randomBoolean()) {
b.array("indices", indices);
} else {
b.field("index", indices[0]);
}
}
b.endObject();
}
b.endObject();
b = shuffleXContent(b);
try (XContentParser parser = createParser(b)) {
AliasActions action = AliasActions.PARSER.apply(parser, null);
assertEquals(AliasActions.Type.REMOVE_INDEX, action.actionType());
assertArrayEquals(indices, action.indices());
assertThat(action.aliases(), arrayWithSize(0));
}
}
use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions in project elasticsearch by elastic.
the class AliasActionsTests method testParseAddDefaultRouting.
public void testParseAddDefaultRouting() throws IOException {
String index = randomAsciiOfLength(5);
String alias = randomAsciiOfLength(5);
Object searchRouting = randomRouting();
Object indexRouting = randomRouting();
XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
b.startObject();
{
b.startObject("add");
{
b.field("index", index);
b.field("alias", alias);
if (randomBoolean()) {
b.field("routing", searchRouting);
b.field("index_routing", indexRouting);
} else {
b.field("search_routing", searchRouting);
b.field("routing", indexRouting);
}
}
b.endObject();
}
b.endObject();
b = shuffleXContent(b);
try (XContentParser parser = createParser(b)) {
AliasActions action = AliasActions.PARSER.apply(parser, null);
assertEquals(AliasActions.Type.ADD, action.actionType());
assertThat(action.indices(), arrayContaining(index));
assertThat(action.aliases(), arrayContaining(alias));
assertEquals(searchRouting.toString(), action.searchRouting());
assertEquals(indexRouting.toString(), action.indexRouting());
}
}
use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions in project elasticsearch by elastic.
the class AliasActionsTests method testEmptyAlias.
public void testEmptyAlias() {
AliasActions.Type type = randomValueOtherThan(AliasActions.Type.REMOVE_INDEX, () -> randomFrom(AliasActions.Type.values()));
Exception e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).alias(null));
assertEquals("[alias] can't be empty string", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).alias(""));
assertEquals("[alias] can't be empty string", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).aliases((String[]) null));
assertEquals("[aliases] can't be empty", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).aliases(new String[0]));
assertEquals("[aliases] can't be empty", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).aliases("test", null));
assertEquals("[aliases] can't contain empty string", e.getMessage());
e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).aliases("test", ""));
assertEquals("[aliases] can't contain empty string", e.getMessage());
}
use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions in project elasticsearch by elastic.
the class AliasActionsTests method testParseAdd.
public void testParseAdd() throws IOException {
String[] indices = generateRandomStringArray(10, 5, false, false);
String[] aliases = generateRandomStringArray(10, 5, false, false);
Map<String, Object> filter = randomBoolean() ? randomMap(5) : null;
Object searchRouting = randomBoolean() ? randomRouting() : null;
Object indexRouting = randomBoolean() ? randomBoolean() ? searchRouting : randomRouting() : null;
XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
b.startObject();
{
b.startObject("add");
{
if (indices.length > 1 || randomBoolean()) {
b.array("indices", indices);
} else {
b.field("index", indices[0]);
}
if (aliases.length > 1 || randomBoolean()) {
b.array("aliases", aliases);
} else {
b.field("alias", aliases[0]);
}
if (filter != null) {
b.field("filter", filter);
}
if (searchRouting != null) {
if (searchRouting.equals(indexRouting)) {
b.field("routing", searchRouting);
} else {
b.field("search_routing", searchRouting);
}
}
if (indexRouting != null && false == indexRouting.equals(searchRouting)) {
b.field("index_routing", indexRouting);
}
}
b.endObject();
}
b.endObject();
b = shuffleXContent(b, "filter");
try (XContentParser parser = createParser(b)) {
AliasActions action = AliasActions.PARSER.apply(parser, null);
assertEquals(AliasActions.Type.ADD, action.actionType());
assertThat(action.indices(), equalTo(indices));
assertThat(action.aliases(), equalTo(aliases));
if (filter == null || filter.isEmpty()) {
assertNull(action.filter());
} else {
assertEquals(XContentFactory.contentBuilder(XContentType.JSON).map(filter).string(), action.filter());
}
assertEquals(Objects.toString(searchRouting, null), action.searchRouting());
assertEquals(Objects.toString(indexRouting, null), action.indexRouting());
}
}
Aggregations