/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you 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 org.elasticsearch.action.index;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.junit.Test;
import static org.hamcrest.Matchers.is;
public class TransportIndexActionIT extends ESSingleNodeTestCase {
/**
* Validates that the autoGeneratedId index request attribute is correctly passed to the
* {@link org.elasticsearch.index.engine.Engine.Create} class.
*/
@Test
public void testPrepareIndexOperationOnPrimaryCreateWithoutAutoGeneratedId() throws Exception {
createIndex("test");
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
IndexService indexService = indicesService.indexService("test");
IndexShard indexShard = indexService.shard(0);
TestIndexRequest indexRequest = new TestIndexRequest("test", "type", "1");
indexRequest.timestamp("0");
indexRequest.source("{}");
indexRequest.opType(IndexRequest.OpType.CREATE);
indexRequest.setCanHaveDuplicates();
Engine.Create create = (Engine.Create) TransportIndexAction.prepareIndexOperationOnPrimary(null,
indexRequest, indexShard);
assertThat(create.canHaveDuplicates(), is(true));
assertThat(create.autoGeneratedId(), is(false));
}
static class TestIndexRequest extends IndexRequest {
boolean canHaveDuplicates = false;
public TestIndexRequest(String index, String type, String id) {
super(index, type, id);
}
public void setCanHaveDuplicates() {
canHaveDuplicates = true;
}
@Override
public boolean canHaveDuplicates() {
return canHaveDuplicates;
}
}
}