Skip to content
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
merged 5 commits into from
Jan 7, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions management/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.kaazing</groupId>
<artifactId>specification.ws</artifactId>
<version>${k3po.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void doSessionCreated(final SessionManagementBean sessionBean) throws Exc
public void doSessionClosed(final SessionManagementBean sessionBean) throws Exception {
if (sessionBean != null) {
sessionBean.doSessionClosed();
sessionBean.doSessionClosedListeners();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ public void doSessionCreated(final SessionManagementBean sessionBean) throws Exc
sessionBean.doSessionCreatedListeners();
}

@Override
public void doSessionClosed(final SessionManagementBean sessionBean) throws Exception {
super.doSessionClosed(sessionBean);
sessionBean.doSessionClosedListeners();
}

@Override
public void doMessageReceived(final SessionManagementBean sessionBean, final Object message) throws Exception {
super.doMessageReceived(sessionBean, message);
Expand Down
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) {
Copy link
Contributor

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?

fail("There should be no sessions but found " + name);
}
}
}
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();
}

}

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();
}

}