Skip to content

Commit ef1239b

Browse files
committed
Hazlecast Caching Problem fix #604
1 parent ae2a3f1 commit ef1239b

File tree

6 files changed

+43
-143
lines changed

6 files changed

+43
-143
lines changed

jooby-hazelcast/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@
8585
<scope>test</scope>
8686
</dependency>
8787

88+
<dependency>
89+
<groupId>org.jooby</groupId>
90+
<artifactId>jooby-netty</artifactId>
91+
<version>${project.version}</version>
92+
<scope>test</scope>
93+
</dependency>
94+
8895
</dependencies>
8996

9097
</project>

jooby-hazelcast/src/main/java/org/jooby/hazelcast/Hcast.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
import org.jooby.Env;
2828
import org.jooby.Jooby.Module;
29-
import org.jooby.internal.hazelcast.HcastManaged;
3029

3130
import com.google.inject.Binder;
31+
import com.hazelcast.core.Hazelcast;
3232
import com.hazelcast.core.HazelcastInstance;
3333
import com.typesafe.config.Config;
3434
import com.typesafe.config.ConfigFactory;
@@ -112,9 +112,11 @@ public void configure(final Env env, final Config conf, final Binder binder) {
112112
configurer.accept(config, conf);
113113
}
114114

115+
HazelcastInstance hcast = Hazelcast.newHazelcastInstance(config);
116+
115117
binder.bind(com.hazelcast.config.Config.class).toInstance(config);
116-
binder.bind(HazelcastInstance.class).toProvider(HcastManaged.class).asEagerSingleton();
117-
env.lifeCycle(HcastManaged.class);
118+
binder.bind(HazelcastInstance.class).toInstance(hcast);
119+
env.onStop(hcast::shutdown);
118120
}
119121

120122
@Override

jooby-hazelcast/src/main/java/org/jooby/internal/hazelcast/HcastManaged.java

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package hazelcast;
2+
3+
import org.jooby.Jooby;
4+
import org.jooby.hazelcast.Hcast;
5+
import org.jooby.hazelcast.HcastSessionStore;
6+
7+
public class HcastApp extends Jooby {
8+
9+
{
10+
use(new Hcast());
11+
session(HcastSessionStore.class);
12+
}
13+
14+
public static void main(final String[] args) {
15+
run(HcastApp::new, args);
16+
}
17+
}

jooby-hazelcast/src/test/java/org/jooby/hazelcast/HcastTest.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.function.Consumer;
77

88
import org.jooby.Env;
9-
import org.jooby.internal.hazelcast.HcastManaged;
109
import org.jooby.test.MockUnit;
1110
import org.junit.Test;
1211
import org.junit.runner.RunWith;
@@ -15,13 +14,14 @@
1514

1615
import com.google.inject.Binder;
1716
import com.google.inject.binder.AnnotatedBindingBuilder;
18-
import com.google.inject.binder.ScopedBindingBuilder;
1917
import com.hazelcast.core.Hazelcast;
2018
import com.hazelcast.core.HazelcastInstance;
2119
import com.typesafe.config.Config;
2220

21+
import javaslang.control.Try.CheckedRunnable;
22+
2323
@RunWith(PowerMockRunner.class)
24-
@PrepareForTest({Hcast.class, Hazelcast.class, com.hazelcast.config.Config.class })
24+
@PrepareForTest({Hcast.class, Hazelcast.class, com.hazelcast.config.Config.class, Hazelcast.class })
2525
public class HcastTest {
2626

2727
@SuppressWarnings("unchecked")
@@ -41,12 +41,15 @@ public class HcastTest {
4141
.mock(AnnotatedBindingBuilder.class);
4242
abbConfig.toInstance(config);
4343

44-
ScopedBindingBuilder sbbHI = unit.mock(ScopedBindingBuilder.class);
45-
sbbHI.asEagerSingleton();
44+
HazelcastInstance hcast = unit.mock(HazelcastInstance.class);
45+
unit.mockStatic(Hazelcast.class);
46+
hcast.shutdown();
4647

48+
expect(Hazelcast.newHazelcastInstance(config)).andReturn(hcast);
4749
AnnotatedBindingBuilder<HazelcastInstance> abbHI = unit
4850
.mock(AnnotatedBindingBuilder.class);
49-
expect(abbHI.toProvider(HcastManaged.class)).andReturn(sbbHI);
51+
abbHI.toInstance(hcast);
52+
unit.registerMock(HazelcastInstance.class, hcast);
5053

5154
Binder binder = unit.get(Binder.class);
5255
expect(binder.bind(com.hazelcast.config.Config.class)).andReturn(abbConfig);
@@ -56,7 +59,7 @@ public class HcastTest {
5659

5760
private MockUnit.Block onStop = unit -> {
5861
Env env = unit.get(Env.class);
59-
expect(env.lifeCycle(HcastManaged.class)).andReturn(env);
62+
expect(env.onStop(unit.capture(CheckedRunnable.class))).andReturn(env);
6063
};
6164

6265
@Test
@@ -67,6 +70,8 @@ public void defaults() throws Exception {
6770
.run(unit -> {
6871
new Hcast()
6972
.configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
73+
}, unit -> {
74+
unit.captured(CheckedRunnable.class).iterator().next().run();
7075
});
7176
}
7277

@@ -84,6 +89,8 @@ public void withConfigurer() throws Exception {
8489
new Hcast()
8590
.doWith(unit.get(Consumer.class))
8691
.configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
92+
}, unit -> {
93+
unit.captured(CheckedRunnable.class).iterator().next().run();
8794
});
8895
}
8996

jooby-hazelcast/src/test/java/org/jooby/internal/hazelcast/HcastManagedTest.java

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)