@@ -91,19 +91,30 @@ public void testGetForUpdate() throws IOException {
91
91
closeShards (primary );
92
92
}
93
93
94
- public void testGetFromTranslogWithSourceMappingOptionsAndStoredFields () throws IOException {
94
+ public void testGetFromTranslogWithStringSourceMappingOptionsAndStoredFields () throws IOException {
95
+ String docToIndex = "{\" foo\" : \" foo\" , \" bar\" : \" bar\" }" ;
96
+ boolean noSource = randomBoolean ();
97
+ String sourceOptions = noSource ? "\" enabled\" : false" : randomBoolean () ? "\" excludes\" : [\" fo*\" ]" : "\" includes\" : [\" ba*\" ]" ;
98
+ runGetFromTranslogWithOptions (docToIndex , sourceOptions , noSource ? "" : "{\" bar\" :\" bar\" }" , "\" text\" " , "foo" );
99
+ }
100
+
101
+ public void testGetFromTranslogWithLongSourceMappingOptionsAndStoredFields () throws IOException {
102
+ String docToIndex = "{\" foo\" : 7, \" bar\" : 42}" ;
103
+ boolean noSource = randomBoolean ();
104
+ String sourceOptions = noSource ? "\" enabled\" : false" : randomBoolean () ? "\" excludes\" : [\" fo*\" ]" : "\" includes\" : [\" ba*\" ]" ;
105
+ runGetFromTranslogWithOptions (docToIndex , sourceOptions , noSource ? "" : "{\" bar\" :42}" , "\" long\" " , 7L );
106
+ }
107
+
108
+ private void runGetFromTranslogWithOptions (String docToIndex , String sourceOptions , String expectedResult , String fieldType ,
109
+ Object expectedFooVal ) throws IOException {
95
110
Settings settings = Settings .builder ().put (IndexMetadata .SETTING_VERSION_CREATED , Version .CURRENT )
96
111
.put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 1 )
97
112
.put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
98
113
.build ();
99
- String docToIndex = "{\" foo\" : \" foo\" , \" bar\" : \" bar\" }" ;
100
- boolean noSource = randomBoolean ();
101
- String sourceOptions = noSource ? "\" enabled\" : false" : randomBoolean () ? "\" excludes\" : [\" fo*\" ]" : "\" includes\" : [\" ba*\" ]" ;
102
- String expectedResult = noSource ? "" : "{\" bar\" :\" bar\" }" ;
114
+
103
115
IndexMetadata metadata = IndexMetadata .builder ("test" )
104
- .putMapping ("{ \" properties\" : { \" foo\" : { \" type\" : \" text\" , \" store\" : true }, " +
105
- "\" bar\" : { \" type\" : \" text\" }}, \" _source\" : { "
106
- + sourceOptions + "}}}" )
116
+ .putMapping ("{ \" properties\" : { \" foo\" : { \" type\" : " + fieldType + ", \" store\" : true }, " +
117
+ "\" bar\" : { \" type\" : " + fieldType + "}}, \" _source\" : { " + sourceOptions + "}}}" )
107
118
.settings (settings )
108
119
.primaryTerm (0 , 1 ).build ();
109
120
IndexShard primary = newShard (new ShardId (metadata .getIndex (), 0 ), true , "n1" , metadata , null );
@@ -138,7 +149,7 @@ public void testGetFromTranslogWithSourceMappingOptionsAndStoredFields() throws
138
149
assertEquals (new String (testGet2 .source () == null ? new byte [0 ] : testGet2 .source (), StandardCharsets .UTF_8 ), expectedResult );
139
150
assertTrue (testGet2 .getFields ().containsKey (RoutingFieldMapper .NAME ));
140
151
assertTrue (testGet2 .getFields ().containsKey ("foo" ));
141
- assertEquals ("foo" , testGet2 .getFields ().get ("foo" ).getValue ());
152
+ assertEquals (expectedFooVal , testGet2 .getFields ().get ("foo" ).getValue ());
142
153
try (Engine .Searcher searcher = primary .getEngine ().acquireSearcher ("test" , Engine .SearcherScope .INTERNAL )) {
143
154
assertEquals (searcher .getIndexReader ().maxDoc (), 2 ); // we read from the translog
144
155
}
@@ -152,7 +163,7 @@ public void testGetFromTranslogWithSourceMappingOptionsAndStoredFields() throws
152
163
assertEquals (new String (testGet2 .source () == null ? new byte [0 ] : testGet2 .source (), StandardCharsets .UTF_8 ), expectedResult );
153
164
assertTrue (testGet2 .getFields ().containsKey (RoutingFieldMapper .NAME ));
154
165
assertTrue (testGet2 .getFields ().containsKey ("foo" ));
155
- assertEquals ("foo" , testGet2 .getFields ().get ("foo" ).getValue ());
166
+ assertEquals (expectedFooVal , testGet2 .getFields ().get ("foo" ).getValue ());
156
167
157
168
closeShards (primary );
158
169
}
0 commit comments