Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ public static boolean analyzeSubscription(final TreeMap<String/* clientId */, Co
boolean startForAWhile = false;
{

String property = prev.getProperties().getProperty(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP);
if (property == null) {
property = String.valueOf(prev.getProperties().get(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP));
Object startTimestamp = prev.getProperties().get(ConsumerRunningInfo.PROP_CONSUMER_START_TIMESTAMP);
if (startTimestamp != null) {
startForAWhile = (System.currentTimeMillis() - Long.parseLong(String.valueOf(startTimestamp))) > (1000 * 60 * 2);
}
startForAWhile = (System.currentTimeMillis() - Long.parseLong(property)) > (1000 * 60 * 2);
}

if (push && startForAWhile) {
Expand Down Expand Up @@ -96,12 +95,12 @@ public static boolean analyzeSubscription(final TreeMap<String/* clientId */, Co
}

public static boolean isPushType(ConsumerRunningInfo consumerRunningInfo) {
String property = consumerRunningInfo.getProperties().getProperty(ConsumerRunningInfo.PROP_CONSUME_TYPE);
Object consumeType = consumerRunningInfo.getProperties().get(ConsumerRunningInfo.PROP_CONSUME_TYPE);

if (property == null) {
property = ((ConsumeType) consumerRunningInfo.getProperties().get(ConsumerRunningInfo.PROP_CONSUME_TYPE)).name();
if (consumeType == null) {
return false;
}
return ConsumeType.valueOf(property) == ConsumeType.CONSUME_PASSIVELY;
return ConsumeType.valueOf(consumeType.toString()) == ConsumeType.CONSUME_PASSIVELY;
}

public static boolean analyzeRebalance(final TreeMap<String/* clientId */, ConsumerRunningInfo> criTable) {
Expand All @@ -110,15 +109,7 @@ public static boolean analyzeRebalance(final TreeMap<String/* clientId */, Consu

public static String analyzeProcessQueue(final String clientId, ConsumerRunningInfo info) {
StringBuilder sb = new StringBuilder();
boolean push = false;
{
String property = info.getProperties().getProperty(ConsumerRunningInfo.PROP_CONSUME_TYPE);

if (property == null) {
property = ((ConsumeType) info.getProperties().get(ConsumerRunningInfo.PROP_CONSUME_TYPE)).name();
}
push = ConsumeType.valueOf(property) == ConsumeType.CONSUME_PASSIVELY;
}
boolean push = isPushType(info);

boolean orderMsg = false;
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,47 @@ public void testAnalyzeSubscription() {
assertThat(result).isTrue();
}

@Test
public void testAnalyzeSubscriptionWithMissingStartTimestamp() {
// a client that does not report its start timestamp keeps the startup grace
// instead of failing the whole analysis
Properties properties = new Properties();
properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, ConsumeType.CONSUME_PASSIVELY.name());
consumerRunningInfo.setProperties(properties);

ConsumerRunningInfo another = new ConsumerRunningInfo();
another.setProperties(new Properties(properties));
another.setSubscriptionSet(new TreeSet<>());

TreeMap<String, ConsumerRunningInfo> table = new TreeMap<>();
table.put("client_id_1", consumerRunningInfo);
table.put("client_id_2", another);

assertThat(ConsumerRunningInfo.analyzeSubscription(table)).isTrue();
}

@Test
public void testAnalyzeMethodsTolerateMissingProperties() {
ConsumerRunningInfo empty = new ConsumerRunningInfo();
empty.setProperties(new Properties());

assertThat(ConsumerRunningInfo.isPushType(empty)).isFalse();
assertThat(ConsumerRunningInfo.analyzeProcessQueue("client_id", empty)).isEmpty();

TreeMap<String, ConsumerRunningInfo> table = new TreeMap<>();
table.put("client_id", empty);
assertThat(ConsumerRunningInfo.analyzeSubscription(table)).isTrue();
}

@Test
public void testIsPushType() {
assertThat(ConsumerRunningInfo.isPushType(consumerRunningInfo)).isFalse();

Properties properties = new Properties();
properties.put(ConsumerRunningInfo.PROP_CONSUME_TYPE, ConsumeType.CONSUME_PASSIVELY.name());
consumerRunningInfo.setProperties(properties);
assertThat(ConsumerRunningInfo.isPushType(consumerRunningInfo)).isTrue();
}


}