Skip to content

Commit d7a440f

Browse files
committed
remove lifecycle methods from Managed objects and PostConstruct/Predestroy objects from Guice fix jooby-project#360
1 parent 4368999 commit d7a440f

73 files changed

Lines changed: 733 additions & 1944 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 9 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.jooby;
22

3-
import java.util.concurrent.CountDownLatch;
4-
53
import javax.annotation.PostConstruct;
64
import javax.inject.Singleton;
75

@@ -15,100 +13,35 @@ public class PostConstructFeature extends ServerFeature {
1513
/** The logging system. */
1614
private static final Logger log = LoggerFactory.getLogger(PostConstructFeature.class);
1715

18-
private static CountDownLatch counter;
19-
20-
public static class ManagedObject {
21-
22-
@PostConstruct
23-
public void start() throws Exception {
24-
log.info("starting: {}", getClass().getName());
25-
counter.countDown();
26-
}
27-
28-
}
29-
3016
@Singleton
3117
public static class SingletonObject {
18+
static int started;
3219

3320
@PostConstruct
3421
public void start() throws Exception {
3522
log.info("starting: {}", this);
36-
counter.countDown();
37-
}
38-
39-
}
40-
41-
public static class ManagedExObject {
42-
43-
@PostConstruct
44-
public void start() throws Exception {
45-
throw new Exception("intentional err");
23+
started += 1;
4624
}
4725

4826
}
4927

5028
{
5129

52-
get("/proto", req -> {
53-
int n = req.param("n").intValue();
54-
for (int i = 0; i < n; i++) {
55-
req.require(ManagedObject.class);
56-
}
57-
return "OK";
58-
});
30+
managed(SingletonObject.class);
5931

6032
get("/singleton", req -> {
61-
int n = req.param("n").intValue();
62-
for (int i = 0; i < n; i++) {
63-
req.require(SingletonObject.class);
64-
}
65-
return "OK";
33+
return SingletonObject.started;
6634
});
67-
68-
get("/protoex", req ->
69-
req.require(ManagedExObject.class));
70-
}
71-
72-
@Test
73-
public void startOneProto() throws Exception {
74-
counter = new CountDownLatch(1);
75-
request()
76-
.get("/proto?n=" + counter.getCount())
77-
.expect("OK");
78-
counter.await();
79-
}
80-
81-
@Test
82-
public void startNSingleton() throws Exception {
83-
counter = new CountDownLatch(1);
84-
request()
85-
.get("/singleton?n=7")
86-
.expect("OK");
87-
counter.await();
8835
}
8936

90-
@Test
91-
public void startTwoProto() throws Exception {
92-
counter = new CountDownLatch(2);
93-
request()
94-
.get("/proto?n=" + counter.getCount())
95-
.expect("OK");
96-
counter.await();
97-
}
37+
static int value = 1;
9838

9939
@Test
100-
public void startNProto() throws Exception {
101-
counter = new CountDownLatch(5);
40+
public void shouldCallPostCConstructMethod() throws Exception {
10241
request()
103-
.get("/proto?n=" + counter.getCount())
104-
.expect("OK");
105-
counter.await();
42+
.get("/singleton")
43+
.expect(value + "");
44+
value += 1;
10645
}
10746

108-
@Test
109-
public void startWithCheckedException() throws Exception {
110-
request()
111-
.get("/protoex")
112-
.expect(500);
113-
}
11447
}

coverage-report/src/test/java/org/jooby/PreDestroyFeature.java

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

0 commit comments

Comments
 (0)