Skip to content

Commit

Permalink
Unit test and adap yaml test
Browse files Browse the repository at this point in the history
  • Loading branch information
andreidan committed Sep 23, 2024
1 parent 7e02c8c commit 11e0bef
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,42 +168,37 @@ generates a consistent id:

- match: {hits.total.value: 9}

- match: { hits.hits.0._id: cn4excfoxSs_KdA5AAABeRnRFAY }
- match: { hits.hits.0.fields._ts_routing_hash: [ cn4exQ ] }
- match: { hits.hits.0._source.@timestamp: 2021-04-28T18:50:03.142Z }
- match: { hits.hits.0._source.k8s.pod.uid: df3145b3-0563-4d3b-a0f7-897eb2876ea9 }
- match: { hits.hits.0._id: cZZNs7B9sSWsyrL5AAABeRnRGTM }
- match: { hits.hits.0._source.@timestamp: 2021-04-28T18:50:04.467Z }
- match: { hits.hits.0._source.k8s.pod.uid: 947e4ced-1786-4e53-9e0c-5c447e959507 }

- match: { hits.hits.1._id: cZZNs7B9sSWsyrL5AAABeRnRGTM }
- match: { hits.hits.1._source.@timestamp: 2021-04-28T18:50:04.467Z }
- match: { hits.hits.1._source.k8s.pod.uid: 947e4ced-1786-4e53-9e0c-5c447e959507 }
- match: { hits.hits.1._id: cn4excfoxSs_KdA5AAABeRnRYiY }
- match: { hits.hits.1._source.@timestamp: 2021-04-28T18:50:23.142Z }
- match: { hits.hits.1._source.k8s.pod.uid: df3145b3-0563-4d3b-a0f7-897eb2876ea9 }

- match: { hits.hits.2._id: cn4excfoxSs_KdA5AAABeRnRYiY }
- match: { hits.hits.2._source.@timestamp: 2021-04-28T18:50:23.142Z }
- match: { hits.hits.2._source.k8s.pod.uid: df3145b3-0563-4d3b-a0f7-897eb2876ea9 }
- match: { hits.hits.2._id: cZZNs7B9sSWsyrL5AAABeRnRZ1M }
- match: { hits.hits.2._source.@timestamp: 2021-04-28T18:50:24.467Z }
- match: { hits.hits.2._source.k8s.pod.uid: 947e4ced-1786-4e53-9e0c-5c447e959507 }

- match: { hits.hits.3._id: cZZNs7B9sSWsyrL5AAABeRnRZ1M }
- match: { hits.hits.3._source.@timestamp: 2021-04-28T18:50:24.467Z }
- match: { hits.hits.3._id: cZZNs7B9sSWsyrL5AAABeRnRtXM }
- match: { hits.hits.3._source.@timestamp: 2021-04-28T18:50:44.467Z }
- match: { hits.hits.3._source.k8s.pod.uid: 947e4ced-1786-4e53-9e0c-5c447e959507 }

- match: { hits.hits.4._id: cZZNs7B9sSWsyrL5AAABeRnRtXM }
- match: { hits.hits.4._source.@timestamp: 2021-04-28T18:50:44.467Z }
- match: { hits.hits.4._source.k8s.pod.uid: 947e4ced-1786-4e53-9e0c-5c447e959507 }
- match: { hits.hits.4._id: cn4excfoxSs_KdA5AAABeRnR11Y }
- match: { hits.hits.4._source.@timestamp: 2021-04-28T18:50:53.142Z }
- match: { hits.hits.4._source.k8s.pod.uid: df3145b3-0563-4d3b-a0f7-897eb2876ea9 }

- match: { hits.hits.5._id: cn4excfoxSs_KdA5AAABeRnR11Y }
- match: { hits.hits.5._source.@timestamp: 2021-04-28T18:50:53.142Z }
- match: { hits.hits.5._id: cn4excfoxSs_KdA5AAABeRnR_mY }
- match: { hits.hits.5._source.@timestamp: 2021-04-28T18:51:03.142Z }
- match: { hits.hits.5._source.k8s.pod.uid: df3145b3-0563-4d3b-a0f7-897eb2876ea9 }

- match: { hits.hits.6._id: cn4excfoxSs_KdA5AAABeRnR_mY }
- match: { hits.hits.6._source.@timestamp: 2021-04-28T18:51:03.142Z }
- match: { hits.hits.6._source.k8s.pod.uid: df3145b3-0563-4d3b-a0f7-897eb2876ea9 }
- match: { hits.hits.6._id: cZZNs7B9sSWsyrL5AAABeRnSA5M }
- match: { hits.hits.6._source.@timestamp: 2021-04-28T18:51:04.467Z }
- match: { hits.hits.6._source.k8s.pod.uid: 947e4ced-1786-4e53-9e0c-5c447e959507 }

- match: { hits.hits.7._id: cZZNs7B9sSWsyrL5AAABeRnSA5M }
- match: { hits.hits.7._source.@timestamp: 2021-04-28T18:51:04.467Z }
- match: { hits.hits.7._id: cZZNs7B9sSWsyrL5AAABeRnS7fM }
- match: { hits.hits.7._source.@timestamp: 2021-04-28T18:52:04.467Z }
- match: { hits.hits.7._source.k8s.pod.uid: 947e4ced-1786-4e53-9e0c-5c447e959507 }

- match: { hits.hits.8._id: cZZNs7B9sSWsyrL5AAABeRnS7fM }
- match: { hits.hits.8._source.@timestamp: 2021-04-28T18:52:04.467Z }
- match: { hits.hits.8._source.k8s.pod.uid: 947e4ced-1786-4e53-9e0c-5c447e959507 }
---
index a new document on top of an old one:
- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public BytesRef parseBytesRef(Object value) {
if (value instanceof BytesRef valueAsBytesRef) {
return valueAsBytesRef;
}
return new BytesRef(value.toString());
return Uid.encodeId(value.toString());
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.index.mapper.DateFieldMapper.Resolution;
import org.elasticsearch.index.mapper.TimeSeriesIdFieldMapper.TimeSeriesIdBuilder;
import org.elasticsearch.index.mapper.TimeSeriesRoutingHashFieldMapper;
import org.elasticsearch.test.ESTestCase;

import java.io.IOException;
Expand All @@ -33,6 +34,8 @@
import static org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileUtils.longEncode;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;

public class DocValueFormatTests extends ESTestCase {

Expand Down Expand Up @@ -388,4 +391,14 @@ public void testParseTsid() throws IOException {
Object tsidBase64 = Base64.getUrlEncoder().withoutPadding().encodeToString(expectedBytes);
assertEquals(tsidFormat, tsidBase64);
}

public void testFormatAndParseTsRoutingHash() throws IOException {
BytesRef tsRoutingHashInput = new BytesRef("cn4exQ");
DocValueFormat docValueFormat = TimeSeriesRoutingHashFieldMapper.INSTANCE.fieldType().docValueFormat(null, ZoneOffset.UTC);
Object formattedValue = docValueFormat.format(tsRoutingHashInput);
// the format method takes BytesRef as input and outputs a String
assertThat(formattedValue, instanceOf(String.class));
// the parse method will output the BytesRef input
assertThat(docValueFormat.parseBytesRef(formattedValue), is(tsRoutingHashInput));
}
}

0 comments on commit 11e0bef

Please sign in to comment.