    1   /**
    2    * Licensed to Neo Technology under one or more contributor
    3    * license agreements. See the NOTICE file distributed with
    4    * this work for additional information regarding copyright
    5    * ownership. Neo Technology licenses this file to you under
    6    * the Apache License, Version 2.0 (the "License"); you may
    7    * not use this file except in compliance with the License.
    8    * You may obtain a copy of the License at
    9    *
    10   * http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing,
    13   * software distributed under the License is distributed on an
    14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    15   * KIND, either express or implied. See the License for the
    16   * specific language governing permissions and limitations
    17   * under the License.
    18   */
    19
    20  package org.neo4j.examples;
    21
    22  import static org.junit.Assert.assertTrue;
    23
    24  import java.util.Date;
    25
    26  import org.junit.Test;
    27  import org.neo4j.graphdb.GraphDatabaseService;
    28  import org.neo4j.jmx.Kernel;
    29  import org.neo4j.kernel.EmbeddedGraphDatabase;
    30
    31  public class JmxTest
    32  {
    33      @Test
    34      public void readJmxProperties()
    35      {
    36          GraphDatabaseService graphDbService = new EmbeddedGraphDatabase(
    37                  "target/jmx-db" );
    38          Date startTime = getStartTimeFromManagementBean( graphDbService );
    39          Date now = new Date();
    40          System.out.println( startTime + " " + now );
    41          assertTrue( startTime.before( now ) || startTime.equals( now ) );
    42      }
    43
    44      // START SNIPPET: getStartTime
    45      private static Date getStartTimeFromManagementBean(
    46              GraphDatabaseService graphDbService )
    47      {
    48          // use EmbeddedGraphDatabase to access management beans
    49          EmbeddedGraphDatabase graphDb = (EmbeddedGraphDatabase) graphDbService;
    50          Kernel kernel = graphDb.getManagementBean( Kernel.class );
    51          Date startTime = kernel.getKernelStartTime();
    52          return startTime;
    53      }
    54      // END SNIPPET: getStartTime
    55  }