Skip to content

Commit

Permalink
Add comment and remove unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Gao Binlong <gbinlong@amazon.com>
  • Loading branch information
gaobinlong committed May 10, 2024
1 parent e3351c5 commit 2464237
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
String index = in.readString();
if (in.getVersion().before(Version.V_2_0_0)) {
int typesSize = in.readVInt();
// if the requested field doesn't exist, type size in the received response from 1.x node is 0
if (typesSize == 0) {
indexMapBuilder.put(index, Collections.emptyMap());
continue;

Check warning on line 123 in server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java#L122-L123

Added lines #L122 - L123 were not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.opensearch.action.admin.indices.mapping.get;

import org.opensearch.Version;
import org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.core.common.Strings;
Expand All @@ -41,7 +40,6 @@
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.test.AbstractWireSerializingTestCase;
import org.opensearch.test.VersionUtils;

import java.io.IOException;
import java.util.Collections;
Expand Down Expand Up @@ -74,51 +72,6 @@ public void testNullFieldMappingToXContent() {
assertEquals("{\"index\":{\"mappings\":{}}}", Strings.toString(MediaTypeRegistry.JSON, response));
}

public void testBwcSerializationWithNullField() throws Exception {
{
Map<String, Map<String, FieldMappingMetadata>> mappings = new HashMap<>();
mappings.put("index", Collections.emptyMap());
final GetFieldMappingsResponse getFieldMappingsResponse = new GetFieldMappingsResponse(mappings);

final Version version = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT);
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(version);
getFieldMappingsResponse.writeTo(out);

try (StreamInput in = out.bytes().streamInput()) {
in.setVersion(version);
int indexSize = in.readVInt();
String indexName = in.readString();
int typeSize = in.readVInt();
assertEquals(indexSize, 1);
assertEquals(indexName, "index");
assertEquals(typeSize, 0);
}
}
}

{
Map<String, Map<String, FieldMappingMetadata>> mappings = new HashMap<>();
String indexName = "index";
mappings.put(indexName, Collections.emptyMap());

final Version version = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT);
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(version);
out.writeVInt(mappings.size());
out.writeString(indexName);
out.writeVInt(mappings.get(indexName).size());

try (StreamInput in = out.bytes().streamInput()) {
in.setVersion(version);
final GetFieldMappingsResponse fieldMappingsResponse = new GetFieldMappingsResponse(in);
assertEquals(fieldMappingsResponse.mappings().size(), 1);
assertEquals("{\"index\":{\"mappings\":{}}}", Strings.toString(MediaTypeRegistry.JSON, fieldMappingsResponse));
}
}
}
}

@Override
protected GetFieldMappingsResponse createTestInstance() {
return new GetFieldMappingsResponse(randomMapping());
Expand Down

0 comments on commit 2464237

Please sign in to comment.