View Javadoc

    1   /**
    2    * Copyright (c) 2002-2011 "Neo Technology,"
    3    * Network Engine for Objects in Lund AB [http://neotechnology.com]
    4    *
    5    * This file is part of Neo4j.
    6    *
    7    * Neo4j is free software: you can redistribute it and/or modify
    8    * it under the terms of the GNU General Public License as published by
    9    * the Free Software Foundation, either version 3 of the License, or
    10   * (at your option) any later version.
    11   *
    12   * This program is distributed in the hope that it will be useful,
    13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15   * GNU General Public License for more details.
    16   *
    17   * You should have received a copy of the GNU General Public License
    18   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    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 ) ); //Reference node is always created in empty dbs
    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  }