/** Test that a node starts and sets SERVICE_UP correctly. */
  @Test(groups = "Integration")
  public void canStartupAndShutdown() {
    solr = app.createAndManageChild(EntitySpec.create(SolrServer.class));
    app.start(ImmutableList.of(testLocation));

    EntityAsserts.assertAttributeEqualsEventually(solr, Startable.SERVICE_UP, true);
    Entities.dumpInfo(app);

    solr.stop();

    EntityAsserts.assertAttributeEqualsEventually(solr, Startable.SERVICE_UP, false);
  }
  /** Test that a core can be created and used with SolrJ client. */
  @Test(groups = "Integration")
  public void testConnection() throws Exception {
    solr =
        app.createAndManageChild(
            EntitySpec.create(SolrServer.class)
                .configure(
                    SolrServer.SOLR_CORE_CONFIG,
                    ImmutableMap.of("example", "classpath://solr/example.tgz")));
    app.start(ImmutableList.of(testLocation));

    EntityAsserts.assertAttributeEqualsEventually(solr, Startable.SERVICE_UP, true);

    SolrJSupport client = new SolrJSupport(solr, "example");

    Iterable<SolrDocument> results = client.getDocuments();
    assertTrue(Iterables.isEmpty(results));

    client.addDocument(MutableMap.<String, Object>of("id", "1", "description", "first"));
    client.addDocument(MutableMap.<String, Object>of("id", "2", "description", "second"));
    client.addDocument(MutableMap.<String, Object>of("id", "3", "description", "third"));
    client.commit();

    results = client.getDocuments();
    assertEquals(Iterables.size(results), 3);
  }
  // TODO BROOKLYN-272, Disabled, because fails non-deterministically in jenkins: BROOKLYN-256
  //    java.lang.AssertionError: Expected: eventually IsEqualTo([starting, running, stopping,
  // stopped]); got most recently: [starting, running, starting, running, stopping, stopped] (waited
  // 1s 11ms 498us 762ns, checked 100)
  //        at org.apache.brooklyn.test.Asserts.fail(Asserts.java:721)
  //        at org.apache.brooklyn.test.Asserts.eventually(Asserts.java:791)
  //        at org.apache.brooklyn.test.Asserts.eventually(Asserts.java:751)
  //        at
  // org.apache.brooklyn.entity.stock.BasicStartableTest.testTransitionsThroughLifecycles(BasicStartableTest.java:170)
  @Test(groups = {"Broken"})
  public void testTransitionsThroughLifecycles() throws Exception {
    BasicStartable startable = app.addChild(EntitySpec.create(BasicStartable.class));
    EntityAsserts.assertAttributeEqualsEventually(
        app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED);

    final RecordingSensorEventListener<Lifecycle> listener =
        new RecordingSensorEventListener<Lifecycle>(true);
    mgmt.getSubscriptionContext(startable)
        .subscribe(startable, Attributes.SERVICE_STATE_ACTUAL, listener);

    app.start(ImmutableList.of(loc1));
    app.config().set(StartableApplication.DESTROY_ON_STOP, false);
    app.stop();

    Iterable<Lifecycle> expected =
        Lists.newArrayList(
            Lifecycle.STARTING, Lifecycle.RUNNING, Lifecycle.STOPPING, Lifecycle.STOPPED);
    Asserts.eventually(
        new Supplier<Iterable<Lifecycle>>() {
          @Override
          public Iterable<Lifecycle> get() {
            return MutableList.copyOf(listener.getEventValuesSortedByTimestamp());
          }
        },
        Predicates.equalTo(expected));
  }