@Test public void cleanDeletingSnapshots() throws Exception { Calendar twoHoursAgo = Calendar.getInstance(); twoHoursAgo.add(Calendar.HOUR, -2); SnapshotInfo deleted = new SnapshotInfo(); deleted.setStatus(StorageProperties.Status.deleted.toString()); deleted.setProgress("100"); deleted.setSizeGb(new Integer(1)); deleted.setStartTime(new Date()); deleted.setVolumeId("vol-0000"); deleted.setSnapshotId("snap-0000"); deleted.setSnapshotLocation("http: deleted.setDeletionTime(twoHoursAgo.getTime()); deleted.setSnapPointId("snap-point-foo"); deleted.setIsOrigin(Boolean.TRUE); SnapshotInfo good = new SnapshotInfo(); good.setStatus(StorageProperties.Status.available.toString()); good.setProgress("100"); good.setSizeGb(new Integer(1)); good.setStartTime(new Date()); good.setVolumeId("vol-0000"); good.setSnapshotId("snap-0001"); good.setSnapshotLocation("http: good.setSnapPointId("snap-point-foo"); good.setIsOrigin(Boolean.TRUE); SnapshotInfo failOne = new SnapshotInfo(); failOne.setStatus(StorageProperties.Status.deleting.toString()); failOne.setProgress("0"); failOne.setSizeGb(new Integer(1)); failOne.setStartTime(new Date()); failOne.setVolumeId("vol-0001"); failOne.setSnapshotId("snap-0002"); failOne.setSnapshotLocation("http: failOne.setSnapPointId("snap-point-foo"); failOne.setIsOrigin(Boolean.TRUE); SnapshotInfo failTwo = new SnapshotInfo(); failTwo.setStatus(StorageProperties.Status.deleting.toString()); failTwo.setProgress("0"); failTwo.setSizeGb(new Integer(1)); failTwo.setStartTime(new Date()); failTwo.setVolumeId("vol-0002"); failTwo.setSnapshotId("snap-0003"); failTwo.setSnapshotLocation("http: failTwo.setSnapPointId("snap-point-foo"); failTwo.setIsOrigin(Boolean.TRUE); try (TransactionResource tran = Entities.transactionFor(SnapshotInfo.class)) { Entities.persist(deleted); Entities.persist(good); Entities.persist(failOne); Entities.persist(failTwo); tran.commit(); } final LogicalStorageManager storageManager = context.mock(LogicalStorageManager.class); context.checking(new Expectations() { { exactly(2).of(storageManager).deleteSnapshot(with(any(String.class)), with(any(String.class))); } }); SnapshotDeleter sct = new SnapshotDeleter(storageManager, BlockStorageUnitTestSupport.createMockS3SnapshotTransfer()); sct.run(); List<SnapshotInfo> remaining; try (TransactionResource tran = Entities.transactionFor(SnapshotInfo.class)) { remaining = Entities.query(new SnapshotInfo()); tran.commit(); } assertTrue("expected to have a result set querying the eucalyptus_storage persistence context", remaining != null); assertTrue("expected all " + remaining.size() + " SnapshotInfos to still exist but found ", remaining.size() == 4); try (TransactionResource tran = Entities.transactionFor(SnapshotInfo.class)) { SnapshotInfo example = new SnapshotInfo(); example.setStatus(StorageProperties.Status.deleted.toString()); remaining = Entities.query(example); tran.commit(); } assertTrue("expected to have a result set querying the eucalyptus_storage persistence context for deleted snapshotinfos", remaining != null); assertTrue("expected " + remaining.size() + " SnapshotInfos with deleted status to exist but found " + remaining.size(), remaining.size() == 3); ExpiredSnapshotCleaner esc = new ExpiredSnapshotCleaner(); esc.run(); try (TransactionResource tran = Entities.transactionFor(SnapshotInfo.class)) { remaining = Entities.query(new SnapshotInfo()); tran.commit(); } assertTrue("expected to have a result set querying the eucalyptus_storage persistence context", remaining != null); assertTrue("expected all three SnapshotInfos to still exist but found ", remaining.size() == 3); try (TransactionResource tran = Entities.transactionFor(SnapshotInfo.class)) { SnapshotInfo example = new SnapshotInfo(); example.setStatus(StorageProperties.Status.deleted.toString()); remaining = Entities.query(example); tran.commit(); } assertTrue("expected to have a result set querying the eucalyptus_storage persistence context for deleted snapshotinfos", remaining != null); assertTrue("expected two SnapshotInfos with deleted status to exist but found " + remaining.size(), remaining.size() == 2); assertTrue("expected a valid deletionTime and snapshot ID other than snap-0000", remaining.get(0).getDeletionTime() != null && !remaining.get(0).getSnapshotId().equals("snap-0000")); assertTrue("expected a valid deletionTime and snapshot ID other than snap-0000", remaining.get(1).getDeletionTime() != null && !remaining.get(0).getSnapshotId().equals("snap-0000")); }
@Override public void run() { deleteFromEBS(); deleteFromOSG(); }
SnapshotDeleter extends CheckerTask { @Override public void run() { deleteFromEBS(); deleteFromOSG(); } }
SnapshotDeleter extends CheckerTask { @Override public void run() { deleteFromEBS(); deleteFromOSG(); } SnapshotDeleter(LogicalStorageManager blockManager);  SnapshotDeleter(LogicalStorageManager blockManager, S3SnapshotTransfer mock); }
SnapshotDeleter extends CheckerTask { @Override public void run() { deleteFromEBS(); deleteFromOSG(); } SnapshotDeleter(LogicalStorageManager blockManager);  SnapshotDeleter(LogicalStorageManager blockManager, S3SnapshotTransfer mock); @Override void run(); }
SnapshotDeleter extends CheckerTask { @Override public void run() { deleteFromEBS(); deleteFromOSG(); } SnapshotDeleter(LogicalStorageManager blockManager);  SnapshotDeleter(LogicalStorageManager blockManager, S3SnapshotTransfer mock); @Override void run();  }