add one more test for hazelcast sessiom, simplify hazelcast instance used for testing as we do not need multicasting

Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
This commit is contained in:
olivier lamy 2018-05-06 09:55:31 +10:00
parent e1d8834295
commit 6451c41aff
2 changed files with 60 additions and 6 deletions

View File

@ -0,0 +1,51 @@
//
// ========================================================================
// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.hazelcast.session;
import org.eclipse.jetty.server.session.AbstractClusteredInvalidationSessionTest;
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
import org.junit.After;
import org.junit.Before;
public class HazelcastClusteredInvalidationSessionTest
extends AbstractClusteredInvalidationSessionTest
{
HazelcastSessionDataStoreFactory factory;
HazelcastTestHelper _testHelper;
@Before
public void setUp()
{
_testHelper = new HazelcastTestHelper();
}
@After
public void shutdown()
{
_testHelper.tearDown();
}
@Override
public SessionDataStoreFactory createSessionDataStoreFactory()
{
return _testHelper.createSessionDataStoreFactory( false );
}
}

View File

@ -24,6 +24,9 @@ import static org.junit.Assert.assertTrue;
import java.util.concurrent.TimeUnit;
import com.hazelcast.config.JoinConfig;
import com.hazelcast.config.MulticastConfig;
import com.hazelcast.config.NetworkConfig;
import org.eclipse.jetty.server.session.SessionData;
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
@ -39,11 +42,14 @@ import com.hazelcast.core.HazelcastInstance;
*/
public class HazelcastTestHelper
{
static String _hazelcastInstanceName = "SESSION_TEST_"+Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
static final String _hazelcastInstanceName = "SESSION_TEST_"+Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
static String _name = Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) );
static HazelcastInstance _instance = Hazelcast.getOrCreateHazelcastInstance( new Config() //
static final String _name = Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) );
static final HazelcastInstance _instance = Hazelcast.getOrCreateHazelcastInstance( new Config() //
.setInstanceName(_hazelcastInstanceName ) //
.setNetworkConfig( new NetworkConfig().setJoin( //
new JoinConfig().setMulticastConfig( //
new MulticastConfig().setEnabled( false ) ) ) ) //
.addMapConfig( new MapConfig().setName(_name) ) );
public HazelcastTestHelper ()
@ -51,12 +57,9 @@ public class HazelcastTestHelper
// noop
}
// definitely not thread safe so tests cannot be executed in parallel
// TODO use ThreadContext variable for this Map name
public SessionDataStoreFactory createSessionDataStoreFactory(boolean onlyClient)
{
HazelcastSessionDataStoreFactory factory = new HazelcastSessionDataStoreFactory();
//_name = Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) );
factory.setOnlyClient( onlyClient );
factory.setMapName(_name);
factory.setHazelcastInstance(_instance);