Skip to content

Instantly share code, notes, and snippets.

View gurbuzali's full-sized avatar
🏠
Working from home

Ali Gurbuz gurbuzali

🏠
Working from home
View GitHub Profile
@gurbuzali
gurbuzali / ClientEntryListenerTest
Last active December 20, 2015 10:08
ClientEntryListenerTest
package gurbuz;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.Config;
import com.hazelcast.config.GroupConfig;
import com.hazelcast.config.MapConfig;
import com.hazelcast.config.NearCacheConfig;
import com.hazelcast.core.*;
@gurbuzali
gurbuzali / ClientReconnnecteTest.java
Created November 13, 2013 15:25
ClientReconnnecteTest
new Thread(){
public void run() {
try {
Thread.sleep(5000);
System.err.println("starting cluster");
HazelcastInstance instance1 = Hazelcast.newHazelcastInstance();
HazelcastInstance instance2 = Hazelcast.newHazelcastInstance();
Thread.sleep(10000);
System.err.println("shutting down cluster");
@gurbuzali
gurbuzali / QueueMemoryLeak.java
Last active December 28, 2015 07:59
Queue Memory Leak Test 3.0
public class QueueMemoryLeak {
static {
System.setProperty(GroupProperties.PROP_WAIT_SECONDS_BEFORE_JOIN, "0");
System.setProperty("java.net.preferIPv4Stack", "true");
System.setProperty("hazelcast.local.localAddress", "127.0.0.1");
System.setProperty("hazelcast.version.check.enabled", "false");
System.setProperty("hazelcast.socket.bind.any", "false");
Random rand = new Random();
@Test
public void testIssue1309() throws InterruptedException {
final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance();
final CountDownLatch latch = new CountDownLatch(1);
new Thread(){
public void run() {
final IQueue<Integer> q = instance1.getQueue("q");
for (int i=1; i<=100; i++){
q.offer(i);
public static void testTopicWithDataSerializable() throws InterruptedException {
final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance();
final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ITopic<ConfigurationChangeMessage> publisher = instance1.getTopic("message");
final ITopic<ConfigurationChangeMessage> consumer = instance2.getTopic("message");
byte[] val = new byte[256];
final Random random = new Random(System.currentTimeMillis());
random.nextBytes(val);
final ConfigurationChangeMessage confMessage = new ConfigurationChangeMessage("type", "name", val);
static void testCluster() throws InterruptedException {
final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance();
final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance();
Thread.sleep(10*60*1000);
final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance();
final HazelcastInstance instance4 = Hazelcast.newHazelcastInstance();
final HazelcastInstance instance5 = Hazelcast.newHazelcastInstance();
@gurbuzali
gurbuzali / client-reconnect
Created December 10, 2013 17:54
2.x client reconnect
public class HazelcastClientUtils {
private static HazelcastClient client = null;
public static void init() {
new Thread() {
public void run() {
while (true) {
if (client == null) {
createClient();
@gurbuzali
gurbuzali / queue-backing0map
Created January 21, 2014 13:38
QueueBackinMap example for 3.x
public class QueueBackedByMap<I> implements IQueue<I> {
final IQueue<Long> queue;
final IMap<Long, I> map;
final IdGenerator idGenerator;
public QueueBackedByMap(HazelcastInstance instance, String name) {
queue = instance.getQueue(name);
map = instance.getMap(name);
idGenerator = instance.getIdGenerator(name);
public class QueueTest {
public static void main(String[] args) throws InterruptedException {
final HazelcastInstance instance = Hazelcast.newHazelcastInstance();
Thread c = new Thread(new Consumer(instance));
Thread p = new Thread(new Producer(instance));
c.start();
Thread.sleep(5000);
static void testContainsKey() throws InterruptedException {
final Config config = new Config();
final MapConfig mapConfig = config.getMapConfig("m");
mapConfig.setTimeToLiveSeconds(900);
mapConfig.setNearCacheConfig(new NearCacheConfig().setTimeToLiveSeconds(900));
final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);