2017-07-21 15:30:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Amazon Software License (the "License").
|
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
|
* A copy of the License is located at
|
|
|
|
|
*
|
|
|
|
|
* http://aws.amazon.com/asl/
|
|
|
|
|
*
|
|
|
|
|
* or in the "license" file accompanying this file. This file 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.
|
|
|
|
|
*/
|
2019-01-15 01:35:35 +00:00
|
|
|
package software.amazon.kinesis.multilang;
|
2016-11-07 19:38:04 +00:00
|
|
|
|
|
|
|
|
import static org.hamcrest.CoreMatchers.equalTo;
|
|
|
|
|
import static org.hamcrest.CoreMatchers.nullValue;
|
|
|
|
|
|
|
|
|
|
import org.hamcrest.Description;
|
|
|
|
|
import org.hamcrest.Matcher;
|
|
|
|
|
import org.hamcrest.TypeSafeDiagnosingMatcher;
|
|
|
|
|
|
2018-08-02 17:57:11 +00:00
|
|
|
import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
|
|
|
|
|
import software.amazon.kinesis.lifecycle.events.InitializationInput;
|
2016-11-07 19:38:04 +00:00
|
|
|
|
|
|
|
|
public class Matchers {
|
|
|
|
|
|
|
|
|
|
public static Matcher<InitializationInput> withInit(InitializationInput initializationInput) {
|
|
|
|
|
return new InitializationInputMatcher(initializationInput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class InitializationInputMatcher extends TypeSafeDiagnosingMatcher<InitializationInput> {
|
|
|
|
|
|
|
|
|
|
private final Matcher<String> shardIdMatcher;
|
|
|
|
|
private final Matcher<ExtendedSequenceNumber> sequenceNumberMatcher;
|
|
|
|
|
|
|
|
|
|
public InitializationInputMatcher(InitializationInput input) {
|
2018-08-02 17:57:11 +00:00
|
|
|
shardIdMatcher = equalTo(input.shardId());
|
|
|
|
|
sequenceNumberMatcher = withSequence(input.extendedSequenceNumber());
|
2016-11-07 19:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean matchesSafely(final InitializationInput item, Description mismatchDescription) {
|
|
|
|
|
|
|
|
|
|
boolean matches = true;
|
2018-08-02 17:57:11 +00:00
|
|
|
if (!shardIdMatcher.matches(item.shardId())) {
|
2016-11-07 19:38:04 +00:00
|
|
|
matches = false;
|
2018-08-02 17:57:11 +00:00
|
|
|
shardIdMatcher.describeMismatch(item.shardId(), mismatchDescription);
|
2016-11-07 19:38:04 +00:00
|
|
|
}
|
2018-08-02 17:57:11 +00:00
|
|
|
if (!sequenceNumberMatcher.matches(item.extendedSequenceNumber())) {
|
2016-11-07 19:38:04 +00:00
|
|
|
matches = false;
|
|
|
|
|
sequenceNumberMatcher.describeMismatch(item, mismatchDescription);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return matches;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void describeTo(Description description) {
|
|
|
|
|
description.appendText("An InitializationInput matching: { shardId: ").appendDescriptionOf(shardIdMatcher)
|
|
|
|
|
.appendText(", sequenceNumber: ").appendDescriptionOf(sequenceNumberMatcher).appendText(" }");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Matcher<ExtendedSequenceNumber> withSequence(ExtendedSequenceNumber extendedSequenceNumber) {
|
|
|
|
|
if (extendedSequenceNumber == null) {
|
|
|
|
|
return nullValue(ExtendedSequenceNumber.class);
|
|
|
|
|
}
|
|
|
|
|
return new ExtendedSequenceNumberMatcher(extendedSequenceNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class ExtendedSequenceNumberMatcher extends TypeSafeDiagnosingMatcher<ExtendedSequenceNumber> {
|
|
|
|
|
|
|
|
|
|
private final Matcher<String> sequenceNumberMatcher;
|
|
|
|
|
private final Matcher<Long> subSequenceNumberMatcher;
|
|
|
|
|
|
|
|
|
|
public ExtendedSequenceNumberMatcher(ExtendedSequenceNumber extendedSequenceNumber) {
|
2018-08-02 17:57:11 +00:00
|
|
|
sequenceNumberMatcher = equalTo(extendedSequenceNumber.sequenceNumber());
|
|
|
|
|
subSequenceNumberMatcher = equalTo(extendedSequenceNumber.subSequenceNumber());
|
2016-11-07 19:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean matchesSafely(ExtendedSequenceNumber item, Description mismatchDescription) {
|
|
|
|
|
|
|
|
|
|
boolean matches = true;
|
2018-08-02 17:57:11 +00:00
|
|
|
if (!sequenceNumberMatcher.matches(item.sequenceNumber())) {
|
2016-11-07 19:38:04 +00:00
|
|
|
matches = false;
|
|
|
|
|
mismatchDescription.appendDescriptionOf(sequenceNumberMatcher);
|
|
|
|
|
}
|
2018-08-02 17:57:11 +00:00
|
|
|
if (!subSequenceNumberMatcher.matches(item.subSequenceNumber())) {
|
2016-11-07 19:38:04 +00:00
|
|
|
matches = false;
|
|
|
|
|
mismatchDescription.appendDescriptionOf(subSequenceNumberMatcher);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return matches;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void describeTo(Description description) {
|
|
|
|
|
description.appendText("An ExtendedSequenceNumber matching: { sequenceNumber: ")
|
|
|
|
|
.appendDescriptionOf(sequenceNumberMatcher).appendText(", subSequenceNumber: ")
|
|
|
|
|
.appendDescriptionOf(subSequenceNumberMatcher);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|