@Test
    public void testSuccess() {
      String id = "entity-id";
      String kind = "entity-kind";

      TombstoneEntity entity = tombstoneBackend.create(kind, id);
      assertThat(entity, notNullValue());
      assertThat(entity, is(tombstoneBackend.getByEntityId(id)));

      tombstoneBackend.delete(entity);
      assertThat(tombstoneBackend.getByEntityId(id), nullValue());
    }
    @Test
    public void testMissingDocumentNoOp() {
      TombstoneEntity entity = new TombstoneEntity();
      entity.setId("missing-id");

      tombstoneBackend.delete(entity);
    }
 @Test
 public void testSuccess() {
   TombstoneEntity entity = tombstoneBackend.create(entityKind, entityId);
   assertThat(entity.getId(), notNullValue());
   assertThat(entity.getEntityId(), is(entityId));
   assertThat(entity.getEntityKind(), is(entityKind));
   assertThat(entity.getTombstoneTime(), greaterThan(0L));
 }
    @Test(
        expectedExceptions = RuntimeException.class,
        expectedExceptionsMessageRegExp = "Multiple tombstones for entity: entity-id")
    public void testMultipleDocuments() {
      String id = "entity-id";
      String kind = "entity-kind";
      buildTombstones(3, id, kind);

      tombstoneBackend.getByEntityId(id);
    }
    @Test
    public void testOneDocument() {
      String id = "entity-id";
      String kind = "entity-kind";
      buildTombstones(1, id, kind);

      TombstoneEntity entity = tombstoneBackend.getByEntityId(id);
      assertThat(entity, notNullValue());
      assertThat(entity.getEntityId(), is(id));
      assertThat(entity.getEntityKind(), is(kind));
      assertThat(entity.getTombstoneTime(), notNullValue());
    }
  @Override
  public void tombstone(NetworkEntity network) throws ExternalException {
    List<Vm> vmsOnNetwork = vmBackend.filterByNetwork(network.getId());
    if (!vmsOnNetwork.isEmpty()) {
      logger.info("There are {} VMs still on network {}", vmsOnNetwork.size(), network.getId());
      return;
    }

    xenonClient.delete(
        NetworkServiceFactory.SELF_LINK + "/" + network.getId(), new NetworkService.State());
    tombstoneBackend.create(Subnet.KIND, network.getId());
    logger.info("network {} tombstoned", network.getId());
  }
 private void buildTombstones(int count, String id, String kind) {
   for (int i = 0; i < count; i++) {
     tombstoneBackend.create(kind, id);
   }
 }
 @Test
 public void testNoDocuments() {
   assertThat(tombstoneBackend.getByEntityId("missing-id"), nullValue());
 }
 @Test(
     expectedExceptions = RuntimeException.class,
     expectedExceptionsMessageRegExp = ".*entityId cannot be null.*")
 public void testError() {
   tombstoneBackend.create(entityKind, null);
 }