-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(issue#912, management) Fixed a memory leak by altering CollectOnlyMa… #841
Merged
dpwspoon
merged 5 commits into
kaazing:develop
from
cmebarrow:issue_912_sessionbean_leak
Jan 7, 2017
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eb7c255
(issue#912, management) Fixed a memory leak by altering CollectOnlyMa…
dd256fa
add jmx session integration test
danibusu 50b69ce
Merge pull request #1 from danibusu/cmebarrow-issue_912_sessionbean_leak
835fec1
(issue#912, management) Fixed JmxSessionIT to enumerate the sessions …
d7b2185
(issue#912, management) Fixed JmxSessionIT to simplify the code (revi…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
134 changes: 134 additions & 0 deletions
134
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,134 @@ | ||
/** | ||
* 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.lang.String.format; | ||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
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 static org.kaazing.gateway.management.test.util.TlsTestUtil.trustStore; | ||
|
||
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 getActiveSessionCountFromJmx() 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); | ||
for (ObjectName name : mbeanNames) { | ||
fail("There should be no sessions but found " + name); | ||
} | ||
} | ||
} |
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(); | ||
} | ||
|
||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use a for statement? The test will stop running after the first failure. Maybe check that the set size is zero?