Skip to content

Commit 32c7abf

Browse files
committed
add smoke test
1 parent 161614e commit 32c7abf

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

server/src/internalClusterTest/java/org/elasticsearch/action/IndicesRequestIT.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
6868
import org.elasticsearch.common.settings.Settings;
6969
import org.elasticsearch.common.util.concurrent.ThreadContext;
70+
import org.elasticsearch.index.IndexSettings;
71+
import org.elasticsearch.index.mapper.DocumentParsingException;
7072
import org.elasticsearch.index.query.QueryBuilders;
7173
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
7274
import org.elasticsearch.plugins.NetworkPlugin;
@@ -83,11 +85,14 @@
8385
import org.elasticsearch.transport.TransportInterceptor;
8486
import org.elasticsearch.transport.TransportRequest;
8587
import org.elasticsearch.transport.TransportRequestHandler;
88+
import org.elasticsearch.xcontent.XContentBuilder;
89+
import org.elasticsearch.xcontent.XContentFactory;
8690
import org.junit.After;
8791
import org.junit.Before;
8892

8993
import java.util.ArrayList;
9094
import java.util.Arrays;
95+
import java.util.Base64;
9196
import java.util.Collection;
9297
import java.util.Collections;
9398
import java.util.HashMap;
@@ -100,6 +105,7 @@
100105

101106
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
102107
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailuresAndResponse;
108+
import static org.hamcrest.Matchers.containsString;
103109
import static org.hamcrest.Matchers.emptyIterable;
104110
import static org.hamcrest.Matchers.equalTo;
105111
import static org.hamcrest.Matchers.greaterThan;
@@ -582,6 +588,27 @@ public void testSearchDfsQueryThenFetch() throws Exception {
582588
);
583589
}
584590

591+
public void testRejectDocumentWithSourceExceedingSizeLimit() throws Exception {
592+
String indexName = "source-limit-test";
593+
int byteLimit = 10;
594+
595+
assertAcked(
596+
prepareCreate(indexName).setSettings(
597+
Settings.builder().put(IndexSettings.MAX_SOURCE_SIZE_BYTES_SETTING.getKey(), byteLimit).build()
598+
)
599+
);
600+
601+
byte[] data = new byte[80];
602+
try (XContentBuilder doc = XContentFactory.jsonBuilder()) {
603+
doc.startObject();
604+
doc.field("value", Base64.getEncoder().encodeToString(data));
605+
doc.endObject();
606+
607+
Exception e = expectThrows(DocumentParsingException.class, () -> { client().prepareIndex(indexName).setSource(doc).get(); });
608+
assertThat(e.getMessage(), containsString("failed to parse, document too large. Max allowed is " + byteLimit + " bytes"));
609+
}
610+
}
611+
585612
private static void assertSameIndices(IndicesRequest originalRequest, String... actions) {
586613
assertSameIndices(originalRequest, false, actions);
587614
}

0 commit comments

Comments
 (0)