/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package software.amazon.flink.example.sink; import org.apache.flink.connector.base.sink.writer.BufferedRequestState; import org.apache.flink.connector.base.sink.writer.RequestEntryWrapper; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import software.amazon.awssdk.services.cloudwatch.model.Dimension; import software.amazon.awssdk.services.cloudwatch.model.MetricDatum; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.Collections; class CloudWatchMetricsStateSerializerTest { @Test void serializeAndDeserialize() throws Exception { MetricDatum expected = MetricDatum.builder() .metricName("metric-name") .timestamp(Instant.now().truncatedTo(ChronoUnit.MILLIS)) .value(12345D) .dimensions( Dimension.builder() .name("dim-1") .value("val-1") .build(), Dimension.builder() .name("dim-2") .value("val-2") .build()) .build(); CloudWatchMetricsStateSerializer serializer = new CloudWatchMetricsStateSerializer(); BufferedRequestState requestState = new BufferedRequestState( Collections.singletonList(new RequestEntryWrapper(expected, 10000))); MetricDatum actual = serializer .deserialize(1, serializer.serialize(requestState)) .getBufferedRequestEntries() .get(0) .getRequestEntry(); Assertions.assertEquals(expected, actual); } }