use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.
the class HttpMonitorIT method testPollStatusReason.
/*
* Test method for 'org.opennms.netmgt.poller.monitors.HttpMonitor.poll(NetworkInterface, Map, Package)'
*/
@Test
public void testPollStatusReason() throws UnknownHostException {
if (m_runTests == false)
return;
Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
Parameter p = new Parameter();
ServiceMonitor monitor = new HttpMonitor();
InetAddress address = DnsUtils.resolveHostname("www.opennms.org");
assertNotNull("Failed to resolved address: www.opennms.org", address);
MonitoredService svc = MonitorTestUtils.getMonitoredService(99, "www.opennms.org", address, "HTTP");
p.setKey("port");
p.setValue("3020");
m.put(p.getKey(), p.getValue());
p.setKey("retry");
p.setValue("1");
m.put(p.getKey(), p.getValue());
p.setKey("timeout");
p.setValue("500");
m.put(p.getKey(), p.getValue());
PollStatus status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
assertNotNull(status.getReason());
/*
// TODO: Enable this portion of the test as soon as there is a IPv6 www.opennms.org
// Try with IPv6
svc = MonitorTestUtils.getMonitoredService(99, "www.opennms.org", "HTTP", true);
status = monitor.poll(svc, m);
MockUtil.println("Reason: "+status.getReason());
assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
assertNotNull(status.getReason());
*/
}
use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.
the class HttpMonitorIT method callTestPollValidVirtualDomain.
public void callTestPollValidVirtualDomain(boolean preferIPv6) throws UnknownHostException {
if (m_runTests == false)
return;
Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
ServiceMonitor monitor = new HttpMonitor();
MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", preferIPv6), "HTTP");
final int port = JUnitHttpServerExecutionListener.getPort();
if (port > 0) {
m.put("port", String.valueOf(port));
} else {
throw new IllegalStateException("Unable to determine what port the HTTP server started on!");
}
m.put("retry", "1");
m.put("timeout", "500");
m.put("host-name", "www.opennms.org");
m.put("url", "/twinkies.html");
m.put("response-text", "~.*twinkies.*");
PollStatus status = monitor.poll(svc, m);
assertEquals("poll status not available", PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.
the class DnsMonitorIT method testDNSIPV4Response.
@Test
public void testDNSIPV4Response() throws UnknownHostException {
final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
final ServiceMonitor monitor = new DnsMonitor();
final MonitoredService svc = MonitorTestUtils.getMonitoredService(99, addr("127.0.0.1"), "DNS");
m.put("port", "9153");
m.put("retry", "1");
m.put("timeout", "3000");
m.put("lookup", "example.com");
final PollStatus status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
use of java.util.concurrent.ConcurrentSkipListMap in project pulsar by yahoo.
the class BrokerClientIntegrationTest method testResetCursor.
@Test(timeOut = 10000, dataProvider = "subType")
public void testResetCursor(SubscriptionType subType) throws Exception {
final RetentionPolicies policy = new RetentionPolicies(60, 52 * 1024);
final DestinationName destName = DestinationName.get("persistent://my-property/use/my-ns/unacked-topic");
final int warmup = 20;
final int testSize = 150;
final List<Message> received = new ArrayList<Message>();
final ConsumerConfiguration consConfig = new ConsumerConfiguration();
final String subsId = "sub";
final NavigableMap<Long, TimestampEntryCount> publishTimeIdMap = new ConcurrentSkipListMap<>();
consConfig.setSubscriptionType(subType);
consConfig.setMessageListener((MessageListener) (Consumer consumer, Message msg) -> {
try {
synchronized (received) {
received.add(msg);
}
consumer.acknowledge(msg);
long publishTime = ((MessageImpl) msg).getPublishTime();
log.info(" publish time is " + publishTime + "," + msg.getMessageId());
TimestampEntryCount timestampEntryCount = publishTimeIdMap.computeIfAbsent(publishTime, (k) -> new TimestampEntryCount(publishTime));
timestampEntryCount.incrementAndGet();
} catch (final PulsarClientException e) {
log.warn("Failed to ack!");
}
});
admin.namespaces().setRetention(destName.getNamespace(), policy);
Consumer consumer = pulsarClient.subscribe(destName.toString(), subsId, consConfig);
final Producer producer = pulsarClient.createProducer(destName.toString());
log.info("warm up started for " + destName.toString());
// send warmup msgs
byte[] msgBytes = new byte[1000];
for (Integer i = 0; i < warmup; i++) {
producer.send(msgBytes);
}
log.info("warm up finished.");
// sleep to ensure receiving of msgs
for (int n = 0; n < 10 && received.size() < warmup; n++) {
Thread.sleep(100);
}
// validate received msgs
Assert.assertEquals(received.size(), warmup);
received.clear();
// publish testSize num of msgs
log.info("Sending more messages.");
for (Integer n = 0; n < testSize; n++) {
producer.send(msgBytes);
Thread.sleep(1);
}
log.info("Sending more messages done.");
Thread.sleep(3000);
long begints = publishTimeIdMap.firstEntry().getKey();
long endts = publishTimeIdMap.lastEntry().getKey();
// find reset timestamp
long timestamp = (endts - begints) / 2 + begints;
timestamp = publishTimeIdMap.floorKey(timestamp);
NavigableMap<Long, TimestampEntryCount> expectedMessages = new ConcurrentSkipListMap<>();
expectedMessages.putAll(publishTimeIdMap.tailMap(timestamp, true));
received.clear();
log.info("reset cursor to " + timestamp + " for topic " + destName.toString() + " for subs " + subsId);
log.info("issuing admin operation on " + admin.getServiceUrl().toString());
List<String> subList = admin.persistentTopics().getSubscriptions(destName.toString());
for (String subs : subList) {
log.info("got sub " + subs);
}
publishTimeIdMap.clear();
// reset the cursor to this timestamp
Assert.assertTrue(subList.contains(subsId));
admin.persistentTopics().resetCursor(destName.toString(), subsId, timestamp);
consumer = pulsarClient.subscribe(destName.toString(), subsId, consConfig);
Thread.sleep(3000);
int totalExpected = 0;
for (TimestampEntryCount tec : expectedMessages.values()) {
totalExpected += tec.numMessages;
}
// validate that replay happens after the timestamp
Assert.assertTrue(publishTimeIdMap.firstEntry().getKey() >= timestamp);
consumer.close();
producer.close();
// validate that expected and received counts match
int totalReceived = 0;
for (TimestampEntryCount tec : publishTimeIdMap.values()) {
totalReceived += tec.numMessages;
}
Assert.assertEquals(totalReceived, totalExpected, "did not receive all messages on replay after reset");
}
use of java.util.concurrent.ConcurrentSkipListMap in project dubbo by alibaba.
the class PojoUtils method createMap.
private static Map createMap(Map src) {
Class<? extends Map> cl = src.getClass();
Map result = null;
if (HashMap.class == cl) {
result = new HashMap();
} else if (Hashtable.class == cl) {
result = new Hashtable();
} else if (IdentityHashMap.class == cl) {
result = new IdentityHashMap();
} else if (LinkedHashMap.class == cl) {
result = new LinkedHashMap();
} else if (Properties.class == cl) {
result = new Properties();
} else if (TreeMap.class == cl) {
result = new TreeMap();
} else if (WeakHashMap.class == cl) {
return new WeakHashMap();
} else if (ConcurrentHashMap.class == cl) {
result = new ConcurrentHashMap();
} else if (ConcurrentSkipListMap.class == cl) {
result = new ConcurrentSkipListMap();
} else {
try {
result = cl.newInstance();
} catch (Exception e) {
/* ignore */
}
if (result == null) {
try {
Constructor<?> constructor = cl.getConstructor(Map.class);
result = (Map) constructor.newInstance(Collections.EMPTY_MAP);
} catch (Exception e) {
/* ignore */
}
}
}
if (result == null) {
result = new HashMap<Object, Object>();
}
return result;
}
Aggregations