Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x

This commit is contained in:
Greg Wilkins 2018-11-12 16:37:48 +01:00
commit 4f4e720a63
5 changed files with 68 additions and 18 deletions

View File

@ -205,6 +205,7 @@ public class HttpClient extends ContainerLifeCycle
@Override
protected void doStart() throws Exception
{
// TODO use #addBean in constructor?
if (sslContextFactory != null)
addBean(sslContextFactory);
@ -213,18 +214,21 @@ public class HttpClient extends ContainerLifeCycle
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setName(name);
executor = threadPool;
addBean(executor);
}
// TODO use #updateBean in #setExecutor
addBean(executor);
if (byteBufferPool == null)
byteBufferPool = new MappedByteBufferPool(2048,
executor instanceof ThreadPool.SizedThreadPool
? ((ThreadPool.SizedThreadPool)executor).getMaxThreads()/2
: ProcessorUtils.availableProcessors()*2);
// TODO use #updateBean in #setByteBufferPool?
addBean(byteBufferPool);
if (scheduler == null)
scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false);
// TODO use #updateBean in #setScheduler?
addBean(scheduler);
transport.setHttpClient(this);
@ -797,7 +801,8 @@ public class HttpClient extends ContainerLifeCycle
*/
public void setExecutor(Executor executor)
{
updateBean(this.executor, executor);
if (isRunning())
LOG.warn("setExecutor called when in {} state",getState());
this.executor = executor;
}

View File

@ -217,12 +217,15 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable, De
private static Constructor<?> findConstructor(Class<?> klass)
{
String pName = klass.getPackage().getName();
String cName = klass.getName().substring(pName.length() + 1);
Package pkg = klass.getPackage();
if (pkg == null)
return null;
String pName = pkg.getName();
String cName = klass.getName().substring(pName.isEmpty() ? 0 : pName.length() + 1);
String mName = pName + ".jmx." + cName + "MBean";
try
{
Class<?> mbeanClass = Loader.loadClass(mName);
Class<?> mbeanClass = Loader.loadClass(klass, mName);
Constructor<?> constructor = ModelMBean.class.isAssignableFrom(mbeanClass)
? mbeanClass.getConstructor()
: mbeanClass.getConstructor(Object.class);
@ -310,12 +313,19 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable, De
// No override of the mbean's ObjectName, so make a generic one.
if (objectName == null)
{
Class<?> klass = obj.getClass();
while (klass.isArray())
klass = klass.getComponentType();
// If no explicit domain, create one.
String domain = _domain;
if (domain == null)
domain = obj.getClass().getPackage().getName();
{
Package pkg = klass.getPackage();
domain = pkg == null ? "" : pkg.getName();
}
String type = obj.getClass().getName().toLowerCase(Locale.ENGLISH);
String type = klass.getName().toLowerCase(Locale.ENGLISH);
int dot = type.lastIndexOf('.');
if (dot >= 0)
type = type.substring(dot + 1);

View File

@ -24,6 +24,7 @@ import javax.management.Attribute;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import javax.management.ObjectName;
import com.acme.Derived;
import com.acme.Managed;
@ -34,6 +35,7 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -54,6 +56,46 @@ public class ObjectMBeanTest
container = null;
}
@Test
public void testMBeanForNull()
{
Object mBean = container.mbeanFor(null);
assertNull(mBean);
}
@Test
public void testMBeanForString()
{
String obj = "foo";
Object mbean = container.mbeanFor(obj);
assertNotNull(mbean);
container.beanAdded(null, obj);
ObjectName objectName = container.findMBean(obj);
assertNotNull(objectName);
}
@Test
public void testMBeanForStringArray()
{
String[] obj = {"a", "b"};
Object mbean = container.mbeanFor(obj);
assertNotNull(mbean);
container.beanAdded(null, obj);
ObjectName objectName = container.findMBean(obj);
assertNotNull(objectName);
}
@Test
public void testMBeanForIntArray()
{
int[] obj = {0, 1, 2};
Object mbean = container.mbeanFor(obj);
assertNotNull(mbean);
container.beanAdded(null, obj);
ObjectName objectName = container.findMBean(obj);
assertNotNull(objectName);
}
@Test
public void testMetaDataCaching()
{

View File

@ -70,13 +70,6 @@ public class ObjectMBeanUtilTest
assertEquals("Test the mbean extended stuff", objectMBeanInfo.getDescription(), "Mbean description must be equal to : Test the mbean extended stuff");
}
@Test
public void testMbeanForNullCheck()
{
Object mBean = container.mbeanFor(null);
assertNull(mBean, "As we are passing null value the output should be null");
}
@Test
public void testGetAttributeMBeanException() throws Exception
{
@ -151,7 +144,7 @@ public class ObjectMBeanUtilTest
}
@Test
public void testSetAttributesForCollectionTypeAttribue() throws Exception
public void testSetAttributesForCollectionTypeAttribute() throws Exception
{
ArrayList<Derived> aliasNames = new ArrayList<>(Arrays.asList(getArrayTypeAttribute()));
@ -231,7 +224,7 @@ public class ObjectMBeanUtilTest
ReflectionException e = assertThrows(ReflectionException.class, () ->
objectMBean.invoke("good", new Object[0], new String[]{"int aone"}));
assertNotNull(e, "An ReflectionException must have occurred by now as we cannot call a methow with wrong signature");
assertNotNull(e, "A ReflectionException must have occurred by now as we cannot call a method with wrong signature");
}
@Test

View File

@ -38,7 +38,7 @@
<logback.version>1.2.3</logback.version>
<jetty-test-policy.version>1.2</jetty-test-policy.version>
<servlet.api.version>4.0.0</servlet.api.version>
<servlet.schema.version>4.0.0</servlet.schema.version>
<servlet.schema.version>4.0.2</servlet.schema.version>
<jsp.version>8.5.33</jsp.version>
<!-- default values are unsupported, but required to be defined for reactor sanity reasons -->
<alpn.version>undefined</alpn.version>
@ -67,7 +67,7 @@
<maven.plugin-tools.version>3.5.2</maven.plugin-tools.version>
<!-- testing -->
<jetty.test.version>5.1</jetty.test.version>
<jetty.test.version>5.2</jetty.test.version>
</properties>
<licenses>