|
16 | 16 |
|
17 | 17 | package org.jacodb.testing; |
18 | 18 |
|
| 19 | +import com.google.common.base.Supplier; |
| 20 | +import com.google.common.base.Suppliers; |
19 | 21 | import com.google.common.collect.Lists; |
20 | 22 | import org.jacodb.api.JcClassOrInterface; |
21 | 23 | import org.jacodb.api.JcClasspath; |
22 | 24 | import org.jacodb.api.JcDatabase; |
23 | | -import org.jacodb.impl.JacoDB; |
24 | | -import org.jacodb.impl.JcSettings; |
25 | | -import org.jacodb.impl.features.Usages; |
26 | 25 | import org.junit.jupiter.api.Test; |
27 | 26 |
|
28 | 27 | import java.io.IOException; |
|
33 | 32 |
|
34 | 33 | public class JavaApiTest { |
35 | 34 |
|
| 35 | + private final Supplier<JcDatabase> db = Suppliers.memoize(() -> { |
| 36 | + try { |
| 37 | + return BaseTestKt.getGlobalDb(); |
| 38 | + } catch (Exception e) { |
| 39 | + throw new RuntimeException(e); |
| 40 | + } |
| 41 | + }); |
| 42 | + |
36 | 43 | @Test |
37 | | - public void createJcdb() throws ExecutionException, InterruptedException, IOException { |
| 44 | + public void createJcdb() { |
38 | 45 | System.out.println("Creating database"); |
39 | | - try (JcDatabase instance = JacoDB.async(new JcSettings().installFeatures(Usages.INSTANCE)).get()) { |
40 | | - System.out.println("Database is ready: " + instance); |
41 | | - } |
| 46 | + JcDatabase database = db.get(); |
| 47 | + assertNotNull(database); |
| 48 | + System.out.println("Database is ready: " + database); |
42 | 49 | } |
43 | 50 |
|
44 | 51 | @Test |
45 | 52 | public void createClasspath() throws ExecutionException, InterruptedException, IOException { |
46 | 53 | System.out.println("Creating database"); |
47 | | - try (JcDatabase instance = JacoDB.async(new JcSettings().installFeatures(Usages.INSTANCE)).get()) { |
48 | | - try (JcClasspath classpath = instance.asyncClasspath(Lists.newArrayList()).get()) { |
49 | | - JcClassOrInterface clazz = classpath.findClassOrNull("java.lang.String"); |
50 | | - assertNotNull(clazz); |
51 | | - assertNotNull(classpath.asyncRefreshed(false).get()); |
52 | | - } |
53 | | - System.out.println("Database is ready: " + instance); |
| 54 | + JcDatabase instance = db.get(); |
| 55 | + try (JcClasspath classpath = instance.asyncClasspath(Lists.newArrayList()).get()) { |
| 56 | + JcClassOrInterface clazz = classpath.findClassOrNull("java.lang.String"); |
| 57 | + assertNotNull(clazz); |
| 58 | + assertNotNull(classpath.asyncRefreshed(false).get()); |
54 | 59 | } |
| 60 | + System.out.println("Database is ready: " + instance); |
55 | 61 | } |
56 | 62 |
|
57 | 63 | @Test |
58 | 64 | public void jcdbOperations() throws ExecutionException, InterruptedException, IOException { |
59 | 65 | System.out.println("Creating database"); |
60 | | - try (JcDatabase instance = JacoDB.async(new JcSettings().installFeatures(Usages.INSTANCE)).get()) { |
61 | | - instance.asyncLoad(getAllClasspath()).get(); |
62 | | - System.out.println("asyncLoad finished"); |
63 | | - instance.asyncRefresh().get(); |
64 | | - System.out.println("asyncRefresh finished"); |
65 | | - instance.asyncRebuildFeatures().get(); |
66 | | - System.out.println("asyncRebuildFeatures finished"); |
67 | | - instance.asyncAwaitBackgroundJobs().get(); |
68 | | - System.out.println("asyncAwaitBackgroundJobs finished"); |
69 | | - } |
| 66 | + JcDatabase instance = db.get(); |
| 67 | + instance.asyncLoad(getAllClasspath()).get(); |
| 68 | + System.out.println("asyncLoad finished"); |
| 69 | + instance.asyncRefresh().get(); |
| 70 | + System.out.println("asyncRefresh finished"); |
| 71 | + instance.asyncRebuildFeatures().get(); |
| 72 | + System.out.println("asyncRebuildFeatures finished"); |
| 73 | + instance.asyncAwaitBackgroundJobs().get(); |
| 74 | + System.out.println("asyncAwaitBackgroundJobs finished"); |
70 | 75 | } |
71 | 76 | } |
0 commit comments