-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
21 changed files
with
1,025 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...or/src/test/java/org/apache/hertzbeat/collector/collect/mq/RocketmqSingleCollectTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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 org.apache.hertzbeat.collector.collect.mq; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import org.apache.hertzbeat.collector.dispatch.DispatchConstants; | ||
import org.apache.hertzbeat.common.entity.job.Metrics; | ||
import org.apache.hertzbeat.common.entity.job.protocol.RocketmqProtocol; | ||
import org.apache.hertzbeat.common.entity.message.CollectRep; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Test case for {@link RocketmqSingleCollectImpl} | ||
*/ | ||
public class RocketmqSingleCollectTest { | ||
private RocketmqSingleCollectImpl collect; | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
collect = new RocketmqSingleCollectImpl(); | ||
} | ||
|
||
@Test | ||
void preCheck() { | ||
// metrics is null | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
collect.preCheck(null); | ||
}); | ||
|
||
// rocketmq is null | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
collect.preCheck(Metrics.builder().build()); | ||
}); | ||
|
||
// rocketmq srv host is null | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
RocketmqProtocol mq = new RocketmqProtocol(); | ||
collect.preCheck(Metrics.builder().rocketmq(mq).build()); | ||
}); | ||
|
||
// rocketmq srv port is null | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
RocketmqProtocol mq = RocketmqProtocol.builder().namesrvHost("127.0.0.1").build(); | ||
collect.preCheck(Metrics.builder().rocketmq(mq).build()); | ||
}); | ||
|
||
// no exception throw | ||
assertDoesNotThrow(() -> { | ||
RocketmqProtocol mq = RocketmqProtocol.builder().namesrvHost("127.0.0.1").namesrvPort("9876").build(); | ||
collect.preCheck(Metrics.builder().rocketmq(mq).build()); | ||
}); | ||
} | ||
|
||
@Test | ||
void destroy() { | ||
assertDoesNotThrow(() -> { | ||
collect.destroy(); | ||
}); | ||
} | ||
|
||
@Test | ||
void collect() { | ||
// metrics is null | ||
assertDoesNotThrow(() -> { | ||
CollectRep.MetricsData.Builder builder = CollectRep.MetricsData.newBuilder(); | ||
collect.collect(builder, 1L, "app", null); | ||
}); | ||
|
||
assertDoesNotThrow(() -> { | ||
CollectRep.MetricsData.Builder builder = CollectRep.MetricsData.newBuilder(); | ||
RocketmqProtocol mq = RocketmqProtocol.builder().namesrvHost("127.0.0.1").namesrvPort("9876").build(); | ||
Metrics metrics = Metrics.builder().rocketmq(mq).build(); | ||
collect.collect(builder, 1L, "app", metrics); | ||
}); | ||
} | ||
|
||
@Test | ||
void supportProtocol() { | ||
assertEquals(DispatchConstants.PROTOCOL_ROCKETMQ, collect.supportProtocol()); | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
collector/src/test/java/org/apache/hertzbeat/collector/collect/mqtt/MqttCollectTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* 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 org.apache.hertzbeat.collector.collect.mqtt; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.apache.hertzbeat.collector.collect.mq.RocketmqSingleCollectImpl; | ||
import org.apache.hertzbeat.collector.dispatch.DispatchConstants; | ||
import org.apache.hertzbeat.common.entity.job.Metrics; | ||
import org.apache.hertzbeat.common.entity.job.protocol.MqttProtocol; | ||
import org.apache.hertzbeat.common.entity.message.CollectRep; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.hivemq.client.mqtt.MqttVersion; | ||
|
||
/** | ||
* Test case for {@link RocketmqSingleCollectImpl} | ||
*/ | ||
public class MqttCollectTest { | ||
private MqttCollectImpl mqttCollect; | ||
private Metrics metrics; | ||
private CollectRep.MetricsData.Builder builder; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
mqttCollect = new MqttCollectImpl(); | ||
MqttProtocol mqtt = MqttProtocol.builder().build(); | ||
metrics = Metrics.builder() | ||
.mqtt(mqtt) | ||
.build(); | ||
builder = CollectRep.MetricsData.newBuilder(); | ||
} | ||
|
||
@Test | ||
void preCheck() { | ||
// host is empty | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
mqttCollect.preCheck(metrics); | ||
}); | ||
|
||
// port is empty | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
MqttProtocol mqtt = MqttProtocol.builder().build(); | ||
mqtt.setHost("example.com"); | ||
metrics.setMqtt(mqtt); | ||
mqttCollect.preCheck(metrics); | ||
}); | ||
|
||
// protocol version is empty | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
MqttProtocol mqtt = MqttProtocol.builder().build(); | ||
mqtt.setHost("example.com"); | ||
mqtt.setPort("1883"); | ||
metrics.setMqtt(mqtt); | ||
mqttCollect.preCheck(metrics); | ||
}); | ||
|
||
// everything is ok | ||
assertDoesNotThrow(() -> { | ||
MqttProtocol mqtt = MqttProtocol.builder().build(); | ||
mqtt.setHost("example.com"); | ||
mqtt.setPort("1883"); | ||
metrics.setMqtt(mqtt); | ||
mqtt.setProtocolVersion("3.1.1"); | ||
mqttCollect.preCheck(metrics); | ||
}); | ||
} | ||
|
||
@Test | ||
void supportProtocol() { | ||
assertEquals(DispatchConstants.PROTOCOL_MQTT, mqttCollect.supportProtocol()); | ||
} | ||
|
||
@Test | ||
void collect() { | ||
// with version 3.1.1 | ||
assertDoesNotThrow(() -> { | ||
MqttProtocol mqtt = MqttProtocol.builder().build(); | ||
mqtt.setHost("example.com"); | ||
mqtt.setPort("1883"); | ||
mqtt.setClientId("clientid"); | ||
mqtt.setTimeout("1"); | ||
mqtt.setProtocolVersion(MqttVersion.MQTT_3_1_1.name()); | ||
|
||
metrics.setMqtt(mqtt); | ||
metrics.setAliasFields(new ArrayList<>()); | ||
|
||
mqttCollect.collect(builder, 1L, "app", metrics); | ||
}); | ||
|
||
|
||
assertDoesNotThrow(() -> { | ||
MqttProtocol mqtt = MqttProtocol.builder().build(); | ||
mqtt.setHost("example.com"); | ||
mqtt.setPort("1883"); | ||
mqtt.setClientId("clientid"); | ||
mqtt.setTimeout("1"); | ||
mqtt.setProtocolVersion(MqttVersion.MQTT_5_0.name()); | ||
|
||
metrics.setMqtt(mqtt); | ||
metrics.setAliasFields(new ArrayList<>()); | ||
|
||
mqttCollect.collect(builder, 1L, "app", metrics); | ||
}); | ||
} | ||
} |
Oops, something went wrong.