368240 - Fixed test.
This commit is contained in:
parent
3a30b4b7a5
commit
74317987c4
|
@ -4,17 +4,15 @@
|
||||||
// All rights reserved. This program and the accompanying materials
|
// All rights reserved. This program and the accompanying materials
|
||||||
// are made available under the terms of the Eclipse Public License v1.0
|
// are made available under the terms of the Eclipse Public License v1.0
|
||||||
// and Apache License v2.0 which accompanies this distribution.
|
// and Apache License v2.0 which accompanies this distribution.
|
||||||
// The Eclipse Public License is available at
|
// The Eclipse Public License is available at
|
||||||
// http://www.eclipse.org/legal/epl-v10.html
|
// http://www.eclipse.org/legal/epl-v10.html
|
||||||
// The Apache License v2.0 is available at
|
// The Apache License v2.0 is available at
|
||||||
// http://www.opensource.org/licenses/apache2.0.php
|
// http://www.opensource.org/licenses/apache2.0.php
|
||||||
// You may elect to redistribute this code under either of these licenses.
|
// You may elect to redistribute this code under either of these licenses.
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
|
|
||||||
package org.eclipse.jetty.monitor;
|
package org.eclipse.jetty.monitor;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
@ -22,7 +20,6 @@ import java.lang.management.ManagementFactory;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -35,13 +32,12 @@ import org.eclipse.jetty.client.security.SimpleRealmResolver;
|
||||||
import org.eclipse.jetty.http.HttpMethods;
|
import org.eclipse.jetty.http.HttpMethods;
|
||||||
import org.eclipse.jetty.http.HttpStatus;
|
import org.eclipse.jetty.http.HttpStatus;
|
||||||
import org.eclipse.jetty.jmx.MBeanContainer;
|
import org.eclipse.jetty.jmx.MBeanContainer;
|
||||||
import org.eclipse.jetty.monitor.JMXMonitor;
|
|
||||||
import org.eclipse.jetty.monitor.jmx.ConsoleNotifier;
|
import org.eclipse.jetty.monitor.jmx.ConsoleNotifier;
|
||||||
import org.eclipse.jetty.monitor.jmx.EventNotifier;
|
import org.eclipse.jetty.monitor.jmx.EventNotifier;
|
||||||
import org.eclipse.jetty.monitor.jmx.EventState;
|
import org.eclipse.jetty.monitor.jmx.EventState;
|
||||||
|
import org.eclipse.jetty.monitor.jmx.EventState.TriggerState;
|
||||||
import org.eclipse.jetty.monitor.jmx.EventTrigger;
|
import org.eclipse.jetty.monitor.jmx.EventTrigger;
|
||||||
import org.eclipse.jetty.monitor.jmx.MonitorAction;
|
import org.eclipse.jetty.monitor.jmx.MonitorAction;
|
||||||
import org.eclipse.jetty.monitor.jmx.EventState.TriggerState;
|
|
||||||
import org.eclipse.jetty.monitor.triggers.AndEventTrigger;
|
import org.eclipse.jetty.monitor.triggers.AndEventTrigger;
|
||||||
import org.eclipse.jetty.monitor.triggers.AttrEventTrigger;
|
import org.eclipse.jetty.monitor.triggers.AttrEventTrigger;
|
||||||
import org.eclipse.jetty.monitor.triggers.EqualToAttrEventTrigger;
|
import org.eclipse.jetty.monitor.triggers.EqualToAttrEventTrigger;
|
||||||
|
@ -61,6 +57,8 @@ import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
|
@ -81,93 +79,93 @@ public class AttrEventTriggerTest
|
||||||
File docRoot = new File("target/test-output/docroot/");
|
File docRoot = new File("target/test-output/docroot/");
|
||||||
docRoot.mkdirs();
|
docRoot.mkdirs();
|
||||||
docRoot.deleteOnExit();
|
docRoot.deleteOnExit();
|
||||||
|
|
||||||
System.setProperty("org.eclipse.jetty.util.log.DEBUG","");
|
System.setProperty("org.eclipse.jetty.util.log.DEBUG","");
|
||||||
_server = new Server();
|
_server = new Server();
|
||||||
|
|
||||||
SelectChannelConnector connector = new SelectChannelConnector();
|
SelectChannelConnector connector = new SelectChannelConnector();
|
||||||
_server.addConnector(connector);
|
_server.addConnector(connector);
|
||||||
|
|
||||||
_handler = new TestHandler();
|
_handler = new TestHandler();
|
||||||
_server.setHandler(_handler);
|
_server.setHandler(_handler);
|
||||||
|
|
||||||
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
|
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
|
||||||
MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
|
MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
|
||||||
mBeanContainer.addBean(Log.getLog());
|
mBeanContainer.addBean(Log.getLog());
|
||||||
|
|
||||||
_counter = _handler.getRequestCounter();
|
_counter = _handler.getRequestCounter();
|
||||||
mBeanContainer.addBean(_counter);
|
mBeanContainer.addBean(_counter);
|
||||||
|
|
||||||
_server.addBean(mBeanContainer);
|
_server.addBean(mBeanContainer, true);
|
||||||
_server.getContainer().addEventListener(mBeanContainer);
|
_server.getContainer().addEventListener(mBeanContainer);
|
||||||
_server.start();
|
_server.start();
|
||||||
|
|
||||||
startClient(null);
|
startClient(null);
|
||||||
|
|
||||||
_monitor = new JMXMonitor();
|
_monitor = new JMXMonitor();
|
||||||
|
|
||||||
int port = _server.getConnectors()[0].getLocalPort();
|
int port = connector.getLocalPort();
|
||||||
_requestUrl = "http://localhost:"+port+ "/";
|
_requestUrl = "http://localhost:"+port+ "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown()
|
public void tearDown()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
stopClient();
|
stopClient();
|
||||||
|
|
||||||
if (_server != null)
|
if (_server != null)
|
||||||
{
|
{
|
||||||
_server.stop();
|
_server.stop();
|
||||||
_server = null;
|
_server = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoCondition()
|
public void testNoCondition()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
long requestCount = 10;
|
long requestCount = 10;
|
||||||
|
|
||||||
AttrEventTrigger<Long> trigger =
|
AttrEventTrigger<Long> trigger =
|
||||||
new AttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter");
|
new AttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter");
|
||||||
|
|
||||||
EventNotifier notifier = new ConsoleNotifier("%s");
|
EventNotifier notifier = new ConsoleNotifier("%s");
|
||||||
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
||||||
|
|
||||||
performTest(action, requestCount, 1000);
|
performTest(action, requestCount, 1000);
|
||||||
|
|
||||||
ResultSet result = new ResultSet(1,requestCount);
|
ResultSet result = new ResultSet(1,requestCount);
|
||||||
assertEquals(result, action.getHits());
|
assertEquals(result, action.getHits());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqual_TRUE()
|
public void testEqual_TRUE()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
long requestCount = 10;
|
long requestCount = 10;
|
||||||
long testValue = 5;
|
long testValue = 5;
|
||||||
|
|
||||||
EqualToAttrEventTrigger<Long> trigger =
|
EqualToAttrEventTrigger<Long> trigger =
|
||||||
new EqualToAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",testValue);
|
new EqualToAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",testValue);
|
||||||
|
|
||||||
EventNotifier notifier = new ConsoleNotifier("%s");
|
EventNotifier notifier = new ConsoleNotifier("%s");
|
||||||
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
||||||
|
|
||||||
performTest(action, requestCount, 1000);
|
performTest(action, requestCount, 1000);
|
||||||
|
|
||||||
ResultSet result = new ResultSet(testValue);
|
ResultSet result = new ResultSet(testValue);
|
||||||
assertEquals(result, action.getHits());
|
assertEquals(result, action.getHits());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqual_FALSE()
|
public void testEqual_FALSE()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
long requestCount = 10;
|
long requestCount = 10;
|
||||||
long testValue = 11;
|
long testValue = 11;
|
||||||
|
|
||||||
EqualToAttrEventTrigger<Long> trigger =
|
EqualToAttrEventTrigger<Long> trigger =
|
||||||
new EqualToAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
new EqualToAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
||||||
testValue);
|
testValue);
|
||||||
|
|
||||||
|
@ -175,19 +173,19 @@ public class AttrEventTriggerTest
|
||||||
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
||||||
|
|
||||||
performTest(action, requestCount, 1000);
|
performTest(action, requestCount, 1000);
|
||||||
|
|
||||||
ResultSet result = new ResultSet();
|
ResultSet result = new ResultSet();
|
||||||
assertEquals(result, action.getHits());
|
assertEquals(result, action.getHits());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLowerLimit()
|
public void testLowerLimit()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
long requestCount = 10;
|
long requestCount = 10;
|
||||||
long testRangeLow = 5;
|
long testRangeLow = 5;
|
||||||
|
|
||||||
GreaterThanAttrEventTrigger<Long> trigger =
|
GreaterThanAttrEventTrigger<Long> trigger =
|
||||||
new GreaterThanAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
new GreaterThanAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
||||||
testRangeLow);
|
testRangeLow);
|
||||||
|
|
||||||
|
@ -195,27 +193,27 @@ public class AttrEventTriggerTest
|
||||||
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
||||||
|
|
||||||
performTest(action, requestCount, 1000);
|
performTest(action, requestCount, 1000);
|
||||||
|
|
||||||
ResultSet result = new ResultSet(6,10);
|
ResultSet result = new ResultSet(6,10);
|
||||||
assertEquals(result, action.getHits());
|
assertEquals(result, action.getHits());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLowerLimitIncl()
|
public void testLowerLimitIncl()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
long requestCount = 10;
|
long requestCount = 10;
|
||||||
long testRangeLow = 5;
|
long testRangeLow = 5;
|
||||||
|
|
||||||
GreaterThanOrEqualToAttrEventTrigger<Long> trigger =
|
GreaterThanOrEqualToAttrEventTrigger<Long> trigger =
|
||||||
new GreaterThanOrEqualToAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
new GreaterThanOrEqualToAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
||||||
testRangeLow);
|
testRangeLow);
|
||||||
|
|
||||||
EventNotifier notifier = new ConsoleNotifier("%s");
|
EventNotifier notifier = new ConsoleNotifier("%s");
|
||||||
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
||||||
|
|
||||||
performTest(action, requestCount, 1000);
|
performTest(action, requestCount, 1000);
|
||||||
|
|
||||||
ResultSet result = new ResultSet(5,10);
|
ResultSet result = new ResultSet(5,10);
|
||||||
assertEquals(result, action.getHits());
|
assertEquals(result, action.getHits());
|
||||||
}
|
}
|
||||||
|
@ -226,8 +224,8 @@ public class AttrEventTriggerTest
|
||||||
{
|
{
|
||||||
long requestCount = 10;
|
long requestCount = 10;
|
||||||
long testRangeHigh = 5;
|
long testRangeHigh = 5;
|
||||||
|
|
||||||
LessThanAttrEventTrigger<Long> trigger =
|
LessThanAttrEventTrigger<Long> trigger =
|
||||||
new LessThanAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
new LessThanAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
||||||
testRangeHigh);
|
testRangeHigh);
|
||||||
|
|
||||||
|
@ -235,11 +233,11 @@ public class AttrEventTriggerTest
|
||||||
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
||||||
|
|
||||||
performTest(action, requestCount, 1000);
|
performTest(action, requestCount, 1000);
|
||||||
|
|
||||||
ResultSet result = new ResultSet(1,4);
|
ResultSet result = new ResultSet(1,4);
|
||||||
assertEquals(result, action.getHits());
|
assertEquals(result, action.getHits());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpperLimitIncl()
|
public void testUpperLimitIncl()
|
||||||
|
@ -247,8 +245,8 @@ public class AttrEventTriggerTest
|
||||||
{
|
{
|
||||||
long requestCount = 10;
|
long requestCount = 10;
|
||||||
long testRangeHigh = 5;
|
long testRangeHigh = 5;
|
||||||
|
|
||||||
LessThanOrEqualToAttrEventTrigger<Long> trigger =
|
LessThanOrEqualToAttrEventTrigger<Long> trigger =
|
||||||
new LessThanOrEqualToAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
new LessThanOrEqualToAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
||||||
testRangeHigh);
|
testRangeHigh);
|
||||||
|
|
||||||
|
@ -256,11 +254,11 @@ public class AttrEventTriggerTest
|
||||||
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
||||||
|
|
||||||
performTest(action, requestCount, 1000);
|
performTest(action, requestCount, 1000);
|
||||||
|
|
||||||
ResultSet result = new ResultSet(1,5);
|
ResultSet result = new ResultSet(1,5);
|
||||||
assertEquals(result, action.getHits());
|
assertEquals(result, action.getHits());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRangeInclusive()
|
public void testRangeInclusive()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -268,20 +266,20 @@ public class AttrEventTriggerTest
|
||||||
long requestCount = 10;
|
long requestCount = 10;
|
||||||
long testRangeLow = 3;
|
long testRangeLow = 3;
|
||||||
long testRangeHigh = 8;
|
long testRangeHigh = 8;
|
||||||
|
|
||||||
RangeInclAttrEventTrigger<Long> trigger =
|
RangeInclAttrEventTrigger<Long> trigger =
|
||||||
new RangeInclAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
new RangeInclAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
||||||
testRangeLow, testRangeHigh);
|
testRangeLow, testRangeHigh);
|
||||||
|
|
||||||
EventNotifier notifier = new ConsoleNotifier("%s");
|
EventNotifier notifier = new ConsoleNotifier("%s");
|
||||||
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
||||||
|
|
||||||
performTest(action, requestCount, 1000);
|
performTest(action, requestCount, 1000);
|
||||||
|
|
||||||
ResultSet result = new ResultSet(testRangeLow,testRangeHigh);
|
ResultSet result = new ResultSet(testRangeLow,testRangeHigh);
|
||||||
assertEquals(result, action.getHits());
|
assertEquals(result, action.getHits());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInsideRangeExclusive()
|
public void testInsideRangeExclusive()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -289,20 +287,20 @@ public class AttrEventTriggerTest
|
||||||
long requestCount = 10;
|
long requestCount = 10;
|
||||||
long testRangeLow = 3;
|
long testRangeLow = 3;
|
||||||
long testRangeHigh = 8;
|
long testRangeHigh = 8;
|
||||||
|
|
||||||
RangeAttrEventTrigger<Long> trigger =
|
RangeAttrEventTrigger<Long> trigger =
|
||||||
new RangeAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
new RangeAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
||||||
testRangeLow, testRangeHigh);
|
testRangeLow, testRangeHigh);
|
||||||
|
|
||||||
EventNotifier notifier = new ConsoleNotifier("%s");
|
EventNotifier notifier = new ConsoleNotifier("%s");
|
||||||
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
||||||
|
|
||||||
performTest(action, requestCount, 1000);
|
performTest(action, requestCount, 1000);
|
||||||
|
|
||||||
ResultSet result = new ResultSet(testRangeLow+1,testRangeHigh-1);
|
ResultSet result = new ResultSet(testRangeLow+1,testRangeHigh-1);
|
||||||
assertEquals(result, action.getHits());
|
assertEquals(result, action.getHits());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRangeComposite()
|
public void testRangeComposite()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -310,23 +308,23 @@ public class AttrEventTriggerTest
|
||||||
long requestCount = 10;
|
long requestCount = 10;
|
||||||
long testRangeLow = 4;
|
long testRangeLow = 4;
|
||||||
long testRangeHigh = 7;
|
long testRangeHigh = 7;
|
||||||
|
|
||||||
GreaterThanAttrEventTrigger<Long> trigger1 =
|
GreaterThanAttrEventTrigger<Long> trigger1 =
|
||||||
new GreaterThanAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
new GreaterThanAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
||||||
testRangeLow);
|
testRangeLow);
|
||||||
LessThanOrEqualToAttrEventTrigger<Long> trigger2 =
|
LessThanOrEqualToAttrEventTrigger<Long> trigger2 =
|
||||||
new LessThanOrEqualToAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
new LessThanOrEqualToAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
||||||
testRangeHigh);
|
testRangeHigh);
|
||||||
AndEventTrigger trigger = new AndEventTrigger(trigger1, trigger2);
|
AndEventTrigger trigger = new AndEventTrigger(trigger1, trigger2);
|
||||||
EventNotifier notifier = new ConsoleNotifier("%s");
|
EventNotifier notifier = new ConsoleNotifier("%s");
|
||||||
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
||||||
|
|
||||||
performTest(action, requestCount, 1000);
|
performTest(action, requestCount, 1000);
|
||||||
|
|
||||||
ResultSet result = new ResultSet(testRangeLow+1,testRangeHigh);
|
ResultSet result = new ResultSet(testRangeLow+1,testRangeHigh);
|
||||||
assertEquals(result, action.getHits());
|
assertEquals(result, action.getHits());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRangeOuter()
|
public void testRangeOuter()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -334,23 +332,23 @@ public class AttrEventTriggerTest
|
||||||
long requestCount = 10;
|
long requestCount = 10;
|
||||||
long testRangeLow = 4;
|
long testRangeLow = 4;
|
||||||
long testRangeHigh = 7;
|
long testRangeHigh = 7;
|
||||||
|
|
||||||
LessThanOrEqualToAttrEventTrigger<Long> trigger1 =
|
LessThanOrEqualToAttrEventTrigger<Long> trigger1 =
|
||||||
new LessThanOrEqualToAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
new LessThanOrEqualToAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
||||||
testRangeLow);
|
testRangeLow);
|
||||||
GreaterThanAttrEventTrigger<Long> trigger2 =
|
GreaterThanAttrEventTrigger<Long> trigger2 =
|
||||||
new GreaterThanAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
new GreaterThanAttrEventTrigger<Long>("org.eclipse.jetty.monitor:type=requestcounter,id=0", "counter",
|
||||||
testRangeHigh);
|
testRangeHigh);
|
||||||
OrEventTrigger trigger = new OrEventTrigger(trigger1, trigger2);
|
OrEventTrigger trigger = new OrEventTrigger(trigger1, trigger2);
|
||||||
EventNotifier notifier = new ConsoleNotifier("%s");
|
EventNotifier notifier = new ConsoleNotifier("%s");
|
||||||
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
CounterAction action = new CounterAction(trigger, notifier, 500, 100);
|
||||||
|
|
||||||
performTest(action, requestCount, 1000);
|
performTest(action, requestCount, 1000);
|
||||||
|
|
||||||
ResultSet result = new ResultSet(1,testRangeLow,testRangeHigh+1, requestCount);
|
ResultSet result = new ResultSet(1,testRangeLow,testRangeHigh+1, requestCount);
|
||||||
assertEquals(result, action.getHits());
|
assertEquals(result, action.getHits());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void performTest(MonitorAction action, long count, long interval)
|
protected void performTest(MonitorAction action, long count, long interval)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -363,17 +361,17 @@ public class AttrEventTriggerTest
|
||||||
ContentExchange getExchange = new ContentExchange();
|
ContentExchange getExchange = new ContentExchange();
|
||||||
getExchange.setURL(_requestUrl);
|
getExchange.setURL(_requestUrl);
|
||||||
getExchange.setMethod(HttpMethods.GET);
|
getExchange.setMethod(HttpMethods.GET);
|
||||||
|
|
||||||
_client.send(getExchange);
|
_client.send(getExchange);
|
||||||
int state = getExchange.waitForDone();
|
int state = getExchange.waitForDone();
|
||||||
|
|
||||||
String content = "";
|
String content = "";
|
||||||
int responseStatus = getExchange.getResponseStatus();
|
int responseStatus = getExchange.getResponseStatus();
|
||||||
if (responseStatus == HttpStatus.OK_200)
|
if (responseStatus == HttpStatus.OK_200)
|
||||||
{
|
{
|
||||||
content = getExchange.getResponseContent();
|
content = getExchange.getResponseContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(HttpStatus.OK_200,responseStatus);
|
assertEquals(HttpStatus.OK_200,responseStatus);
|
||||||
Thread.sleep(interval);
|
Thread.sleep(interval);
|
||||||
}
|
}
|
||||||
|
@ -382,12 +380,12 @@ public class AttrEventTriggerTest
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.sleep(interval);
|
Thread.sleep(interval);
|
||||||
|
|
||||||
_monitor.removeActions(action);
|
_monitor.removeActions(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void startClient(Realm realm)
|
protected void startClient(Realm realm)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -397,7 +395,7 @@ public class AttrEventTriggerTest
|
||||||
_client.setRealmResolver(new SimpleRealmResolver(realm));
|
_client.setRealmResolver(new SimpleRealmResolver(realm));
|
||||||
_client.start();
|
_client.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void stopClient()
|
protected void stopClient()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -412,7 +410,7 @@ public class AttrEventTriggerTest
|
||||||
extends AbstractHandler
|
extends AbstractHandler
|
||||||
{
|
{
|
||||||
private RequestCounter _counter = new RequestCounter();
|
private RequestCounter _counter = new RequestCounter();
|
||||||
|
|
||||||
public void handle(String target, Request baseRequest,
|
public void handle(String target, Request baseRequest,
|
||||||
HttpServletRequest request, HttpServletResponse response)
|
HttpServletRequest request, HttpServletResponse response)
|
||||||
throws IOException, ServletException
|
throws IOException, ServletException
|
||||||
|
@ -421,40 +419,40 @@ public class AttrEventTriggerTest
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_counter.increment();
|
_counter.increment();
|
||||||
|
|
||||||
response.setContentType("text/plain");
|
response.setContentType("text/plain");
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
PrintWriter writer = response.getWriter();
|
PrintWriter writer = response.getWriter();
|
||||||
writer.println("===TEST RESPONSE===");
|
writer.println("===TEST RESPONSE===");
|
||||||
baseRequest.setHandled(true);
|
baseRequest.setHandled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestCounter getRequestCounter()
|
public RequestCounter getRequestCounter()
|
||||||
{
|
{
|
||||||
return _counter;
|
return _counter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class ResultSet extends TreeSet<Long>
|
protected static class ResultSet extends TreeSet<Long>
|
||||||
{
|
{
|
||||||
public ResultSet() {}
|
public ResultSet() {}
|
||||||
|
|
||||||
public ResultSet(long value)
|
public ResultSet(long value)
|
||||||
{
|
{
|
||||||
add(value);
|
add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultSet(long start, long end)
|
public ResultSet(long start, long end)
|
||||||
{
|
{
|
||||||
addEntries(start, end);
|
addEntries(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultSet(long start, long pause, long resume, long end)
|
public ResultSet(long start, long pause, long resume, long end)
|
||||||
{
|
{
|
||||||
addEntries(start, pause);
|
addEntries(start, pause);
|
||||||
addEntries(resume, end);
|
addEntries(resume, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEntries(long start, long stop)
|
public void addEntries(long start, long stop)
|
||||||
{
|
{
|
||||||
if (start > 0 && stop > 0)
|
if (start > 0 && stop > 0)
|
||||||
|
@ -471,23 +469,23 @@ public class AttrEventTriggerTest
|
||||||
return (this.size() == set.size()) && containsAll(set);
|
return (this.size() == set.size()) && containsAll(set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class CounterAction
|
protected static class CounterAction
|
||||||
extends MonitorAction
|
extends MonitorAction
|
||||||
{
|
{
|
||||||
private ResultSet _hits = new ResultSet();
|
private ResultSet _hits = new ResultSet();
|
||||||
|
|
||||||
public CounterAction(EventTrigger trigger, EventNotifier notifier, long interval, long delay)
|
public CounterAction(EventTrigger trigger, EventNotifier notifier, long interval, long delay)
|
||||||
{
|
{
|
||||||
super(trigger, notifier, interval, delay);
|
super(trigger, notifier, interval, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(EventTrigger trigger, EventState<?> state, long timestamp)
|
public void execute(EventTrigger trigger, EventState<?> state, long timestamp)
|
||||||
{
|
{
|
||||||
if (trigger != null && state != null)
|
if (trigger != null && state != null)
|
||||||
{
|
{
|
||||||
Collection<?> values = state.values();
|
Collection<?> values = state.values();
|
||||||
|
|
||||||
Iterator<?> it = values.iterator();
|
Iterator<?> it = values.iterator();
|
||||||
while(it.hasNext())
|
while(it.hasNext())
|
||||||
{
|
{
|
||||||
|
@ -500,7 +498,7 @@ public class AttrEventTriggerTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultSet getHits()
|
public ResultSet getHits()
|
||||||
{
|
{
|
||||||
return _hits;
|
return _hits;
|
||||||
|
|
Loading…
Reference in New Issue