fix bug when adding to BulkRequest with no TTL, add simple unit test for that

This commit is contained in:
Benjamin Devèze 2011-09-13 17:57:38 +02:00 committed by Shay Banon
parent a84eb1fc8f
commit e52dbf4fda
4 changed files with 45 additions and 2 deletions

View File

@ -115,7 +115,7 @@ public class BulkRequest implements ActionRequest {
String routing = null;
String parent = null;
String timestamp = null;
long ttl = -1;
Long ttl = null;
String opType = null;
long version = 0;
VersionType versionType = VersionType.INTERNAL;

View File

@ -289,7 +289,10 @@ public class IndexRequest extends ShardReplicationOperationRequest {
}
// Sets the relative ttl value. It musts be > 0 as it makes little sense otherwise.
public IndexRequest ttl(long ttl) throws ElasticSearchGenerationException {
public IndexRequest ttl(Long ttl) throws ElasticSearchGenerationException {
if (ttl == null) {
return this;
}
if (ttl <= 0) {
throw new ElasticSearchIllegalArgumentException("TTL value must be > 0. Illegal value provided [" + ttl + "]");
}

View File

@ -0,0 +1,35 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search 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.bulk;
import org.testng.annotations.Test;
import static org.elasticsearch.common.io.Streams.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
public class BulkActionTests {
@Test public void testSimpleBulk() throws Exception {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk.json");
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(bulkAction.getBytes(), 0, bulkAction.length(), true);
assertThat(bulkRequest.numberOfActions(), equalTo(3));
}
}

View File

@ -0,0 +1,5 @@
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
{ "field1" : "value3" }