1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.neo4j.server.rrd;
21
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.greaterThan;
24 import static org.hamcrest.core.Is.is;
25
26 import java.io.IOException;
27
28 import javax.management.MalformedObjectNameException;
29
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.neo4j.graphdb.Transaction;
34 import org.neo4j.kernel.ImpermanentGraphDatabase;
35
36 public class NodeIdsInUseSampleableTest
37 {
38 public ImpermanentGraphDatabase db;
39 public NodeIdsInUseSampleable sampleable;
40
41 @Test
42 public void emptyDbHasZeroNodesInUse() throws IOException, MalformedObjectNameException
43 {
44 assertThat( sampleable.getValue(), is( 1L ) );
45 }
46
47 @Test
48 public void addANodeAndSampleableGoesUp() throws IOException, MalformedObjectNameException
49 {
50 long oldValue = sampleable.getValue();
51
52 createNode( db );
53
54 assertThat( sampleable.getValue(), greaterThan( oldValue ) );
55 }
56
57 private void createNode( ImpermanentGraphDatabase db )
58 {
59 Transaction tx = db.beginTx();
60 db.createNode();
61 tx.success();
62 tx.finish();
63 }
64
65 @Before
66 public void setUp() throws Exception
67 {
68 db = new ImpermanentGraphDatabase();
69 sampleable = new NodeIdsInUseSampleable( db );
70 }
71
72 @After
73 public void shutdown()
74 {
75 db.shutdown();
76 }
77 }