-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #841 from cmebarrow/issue_912_sessionbean_leak
(issue#912, management) Fixed a memory leak by altering CollectOnlyMa…
- Loading branch information
Showing
6 changed files
with
209 additions
and
6 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
128 changes: 128 additions & 0 deletions
128
management/src/test/java/org/kaazing/gateway/management/jmx/JmxSessionIT.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,128 @@ | ||
/** | ||
* Copyright 2007-2016, Kaazing Corporation. All rights reserved. | ||
* | ||
* Licensed 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.kaazing.gateway.management.jmx; | ||
|
||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.kaazing.gateway.management.test.util.TlsTestUtil.getKeystoreFileLocation; | ||
import static org.kaazing.gateway.management.test.util.TlsTestUtil.keyStore; | ||
import static org.kaazing.gateway.management.test.util.TlsTestUtil.password; | ||
|
||
import java.security.KeyStore; | ||
import java.util.Set; | ||
|
||
import javax.management.MBeanServerConnection; | ||
import javax.management.ObjectName; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.RuleChain; | ||
import org.junit.rules.TestRule; | ||
import org.kaazing.gateway.management.test.util.JmxRule; | ||
import org.kaazing.gateway.server.test.GatewayRule; | ||
import org.kaazing.gateway.server.test.config.GatewayConfiguration; | ||
import org.kaazing.gateway.server.test.config.builder.GatewayConfigurationBuilder; | ||
import org.kaazing.k3po.junit.annotation.ScriptProperty; | ||
import org.kaazing.k3po.junit.annotation.Specification; | ||
import org.kaazing.k3po.junit.rules.K3poRule; | ||
import org.kaazing.test.util.ITUtil; | ||
import org.kaazing.test.util.MethodExecutionTrace; | ||
|
||
public class JmxSessionIT { | ||
|
||
private static final String ECHO_WSN_SERVICE = "echoWsn"; | ||
private static final String JMX_URI = "service:jmx:rmi:///jndi/rmi://localhost:2020/jmxrmi"; | ||
private static final String WS_URI = "ws://localhost:8001/echo"; | ||
|
||
protected static final String ADMIN = "AUTHORIZED"; | ||
private final KeyStore keyStore = keyStore(); | ||
private final char[] password = password(); | ||
|
||
private K3poRule k3po = new K3poRule().setScriptRoot("org/kaazing/specification/ws/closing"); | ||
|
||
private GatewayRule gateway = new GatewayRule() { | ||
{ | ||
// @formatter:off | ||
@SuppressWarnings("deprecation") | ||
GatewayConfiguration configuration = | ||
new GatewayConfigurationBuilder() | ||
.service() | ||
.name(ECHO_WSN_SERVICE) | ||
.accept(WS_URI) | ||
.type("echo") | ||
.crossOrigin() | ||
.allowOrigin("*") | ||
.done() | ||
.done() | ||
.service() | ||
.property("connector.server.address", "jmx://localhost:2020/") | ||
.type("management.jmx") | ||
.authorization() | ||
.requireRole(ADMIN) | ||
.done() | ||
.realmName("jmxrealm") | ||
.done() | ||
.security() | ||
.keyStore(keyStore) | ||
.keyStorePassword(password) | ||
.keyStoreFile(getKeystoreFileLocation()) | ||
.realm() | ||
.name("jmxrealm") | ||
.description("realm for jmx") | ||
.httpChallengeScheme("Application Basic") | ||
.loginModule() | ||
.type("class:org.kaazing.gateway.management.test.util.TestLoginModule") | ||
.success("requisite") | ||
.done() | ||
.done() | ||
.done() | ||
.done(); | ||
// @formatter:on | ||
init(configuration); | ||
} | ||
}; | ||
|
||
private JmxRule jmxConnection = new JmxRule(JMX_URI); | ||
private TestRule timeout = ITUtil.timeoutRule(10, SECONDS); | ||
private TestRule trace = new MethodExecutionTrace(); | ||
|
||
@Rule | ||
public TestRule chain = RuleChain.outerRule(trace).around(gateway).around(k3po).around(jmxConnection).around(timeout); | ||
|
||
@Specification("client.send.empty.close.frame/handshake.request.and.frame") | ||
@ScriptProperty("location 'http://localhost:8001/echo'") | ||
@Test | ||
public void sessionWhichHasClosedShouldBeRemovedFromCurrentSessionCountAndActiveSessions() throws Exception { | ||
k3po.finish(); | ||
|
||
// to make sure jmx is updated | ||
Thread.sleep(1000); | ||
|
||
MBeanServerConnection mbeanServerConn = jmxConnection.getConnection(); | ||
ObjectName summaryBeansObjectNamePattern = new ObjectName( | ||
"org.kaazing.gateway.server.management:root=gateways,subtype=services,serviceType=echo,serviceId=\"" | ||
+ ECHO_WSN_SERVICE + "\",name=summary,*"); | ||
Set<ObjectName> mbeanNames = mbeanServerConn.queryNames(summaryBeansObjectNamePattern, null); | ||
assertEquals(1, mbeanNames.size()); | ||
ObjectName summaryBean = mbeanNames.iterator().next(); | ||
assertEquals(Long.valueOf(1), (Long) mbeanServerConn.getAttribute(summaryBean, "NumberOfCumulativeSessions")); | ||
assertEquals(Long.valueOf(0), (Long) mbeanServerConn.getAttribute(summaryBean, "NumberOfCurrentSessions")); | ||
|
||
mbeanNames = mbeanServerConn.queryNames( | ||
ObjectName.getInstance("*:serviceType=echo,name=sessions,*"), null); | ||
assertEquals("The set of sessions should be empty", 0, mbeanNames.size()); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...java/org/kaazing/gateway/management/session/CollectOnlyManagementSessionStrategyTest.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,49 @@ | ||
/** | ||
* Copyright 2007-2016, Kaazing Corporation. All rights reserved. | ||
* | ||
* Licensed 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.kaazing.gateway.management.session; | ||
|
||
import org.jmock.integration.junit4.JUnitRuleMockery; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.kaazing.gateway.transport.test.Expectations; | ||
|
||
public class CollectOnlyManagementSessionStrategyTest { | ||
|
||
@Rule | ||
public JUnitRuleMockery context = new JUnitRuleMockery(); | ||
|
||
private final ManagementSessionStrategy strategy = getManagementSessionStrategy(); | ||
|
||
@Test | ||
public void doSessionClosed_shouldCallSessionCloseListeners() throws Exception { | ||
final SessionManagementBean sessionBean = context.mock(SessionManagementBean.class, "sessionBean"); | ||
|
||
context.checking(new Expectations() { | ||
{ | ||
oneOf(sessionBean).doSessionClosed(); | ||
oneOf(sessionBean).doSessionClosedListeners(); | ||
} | ||
}); | ||
|
||
strategy.doSessionClosed(sessionBean); | ||
} | ||
|
||
protected ManagementSessionStrategy getManagementSessionStrategy() { | ||
return new CollectOnlyManagementSessionStrategy(); | ||
} | ||
|
||
} | ||
|
25 changes: 25 additions & 0 deletions
25
...c/test/java/org/kaazing/gateway/management/session/FullManagementSessionStrategyTest.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,25 @@ | ||
/** | ||
* Copyright 2007-2016, Kaazing Corporation. All rights reserved. | ||
* | ||
* Licensed 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.kaazing.gateway.management.session; | ||
|
||
public class FullManagementSessionStrategyTest extends CollectOnlyManagementSessionStrategyTest { | ||
|
||
protected ManagementSessionStrategy getManagementSessionStrategy() { | ||
return new FullManagementSessionStrategy(); | ||
} | ||
|
||
} | ||
|