|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * |
| 4 | + * The OpenSearch Contributors require contributions made to |
| 5 | + * this file be licensed under the Apache-2.0 license or a |
| 6 | + * compatible open source license. |
| 7 | + */ |
| 8 | + |
| 9 | +package org.opensearch.cluster.metadata; |
| 10 | + |
| 11 | +import org.opensearch.Version; |
| 12 | +import org.opensearch.cluster.metadata.ComposableIndexTemplate.DataStreamTemplate; |
| 13 | +import org.opensearch.common.io.stream.BytesStreamOutput; |
| 14 | +import org.opensearch.common.io.stream.StreamInput; |
| 15 | +import org.opensearch.common.io.stream.Writeable; |
| 16 | +import org.opensearch.common.xcontent.XContentParser; |
| 17 | +import org.opensearch.test.AbstractSerializingTestCase; |
| 18 | +import org.opensearch.test.VersionUtils; |
| 19 | + |
| 20 | +import java.io.IOException; |
| 21 | + |
| 22 | +import static org.hamcrest.Matchers.equalTo; |
| 23 | + |
| 24 | +public class DataStreamTemplateTests extends AbstractSerializingTestCase<DataStreamTemplate> { |
| 25 | + |
| 26 | + @Override |
| 27 | + protected DataStreamTemplate doParseInstance(XContentParser parser) throws IOException { |
| 28 | + return DataStreamTemplate.fromXContent(parser); |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + protected Writeable.Reader<DataStreamTemplate> instanceReader() { |
| 33 | + return DataStreamTemplate::new; |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + protected DataStreamTemplate createTestInstance() { |
| 38 | + return new DataStreamTemplate(new DataStream.TimestampField("timestamp_" + randomAlphaOfLength(5))); |
| 39 | + } |
| 40 | + |
| 41 | + public void testBackwardCompatibleSerialization() throws Exception { |
| 42 | + Version version = VersionUtils.getPreviousVersion(Version.V_1_0_0); |
| 43 | + BytesStreamOutput out = new BytesStreamOutput(); |
| 44 | + out.setVersion(version); |
| 45 | + |
| 46 | + DataStreamTemplate outTemplate = new DataStreamTemplate(); |
| 47 | + outTemplate.writeTo(out); |
| 48 | + assertThat(out.size(), equalTo(0)); |
| 49 | + |
| 50 | + StreamInput in = out.bytes().streamInput(); |
| 51 | + in.setVersion(version); |
| 52 | + DataStreamTemplate inTemplate = new DataStreamTemplate(in); |
| 53 | + |
| 54 | + assertThat(inTemplate, equalTo(outTemplate)); |
| 55 | + } |
| 56 | + |
| 57 | +} |
0 commit comments