コード例 #1
0
 @Test
 public void TestPurgeServiceRunLogNoLimit() {
   Calendar cal = Calendar.getInstance(Locale.getDefault());
   cal.add(Calendar.DATE, -400);
   Date start1 = cal.getTime();
   cal.add(Calendar.HOUR, 1);
   Date end1 = cal.getTime();
   ServiceRunProvider.ServiceRun r1 = new ServiceRunProvider.ServiceRun(1, start1, end1, 0, 0);
   cal.add(Calendar.DATE, 200);
   Date start2 = cal.getTime();
   cal.add(Calendar.HOUR, 1);
   Date end2 = cal.getTime();
   ServiceRunProvider.ServiceRun r2 = new ServiceRunProvider.ServiceRun(2, start2, end2, 2, 1);
   long rid1 = ServiceRunProvider.InsertRow(myDb, r1);
   long rid2 = ServiceRunProvider.InsertRow(myDb, r2);
   // insert calls
   LoggedCallProvider.InsertRow(
       myDb, new LoggedCallProvider.LoggedCall(rid1, null, "123", "dummy"));
   LoggedCallProvider.InsertRow(
       myDb, new LoggedCallProvider.LoggedCall(rid2, null, "456", "dummy"));
   Cursor latest = ServiceRunProvider.LatestRuns(myDb, -1);
   assertEquals("There should be two records", 2, latest.getCount());
   Cursor calls = LoggedCallProvider.LatestCalls(myDb, -1);
   assertEquals("There should be two records", 2, latest.getCount());
   ServiceRunProvider.PurgeLog(myDb, myContext, "no limit");
   latest = ServiceRunProvider.LatestRuns(myDb, -1);
   assertEquals("No purging", 2, latest.getCount());
   assertEquals("No purging", 2, calls.getCount());
   latest.close();
   calls.close();
 }
コード例 #2
0
 @Test
 public void TestRecordWhenStartStoppingTheService() {
   // ...when the service starts
   long id = ServiceRunProvider.InsertAtServiceStart(myDb);
   // end of service
   ServiceRunProvider.UpdateAtServiceStop(myDb, id, 2, 1);
   // service starts again
   id = ServiceRunProvider.InsertAtServiceStart(myDb);
   // 2nd end of service
   ServiceRunProvider.UpdateAtServiceStop(myDb, id, 3, 1);
   ServiceRunProvider.ServiceRun latest = ServiceRunProvider.LatestRun(myDb);
   // tests
   assertEquals("There should be two records", 2, latest.getId());
   assertEquals("Total of 3 calls received", 3, latest.getNumReceived());
   assertEquals("Total of 1 event triggered", 1, latest.getNumTriggered());
 }
コード例 #3
0
 @Test
 public void GetLatestServiceRunWhenTableIsEmpty() {
   ServiceRunProvider.ServiceRun latest = ServiceRunProvider.LatestRun(myDb);
   assertEquals("dummy id", 0, latest.getId());
   assertEquals("received", 0, latest.getNumReceived());
   assertEquals("triggered", 0, latest.getNumTriggered());
 }
コード例 #4
0
 @Test
 public void GetLatestServiceRunWhenTableIsNotEmpty() {
   Calendar cal = Calendar.getInstance(Locale.getDefault());
   Date start = cal.getTime();
   cal.add(Calendar.HOUR, 1);
   Date end = cal.getTime();
   ServiceRunProvider.InsertRow(myDb, new ServiceRunProvider.ServiceRun(-1, start, end, 2, 1));
   cal.add(Calendar.HOUR, 1);
   start = cal.getTime();
   cal.add(Calendar.HOUR, 1);
   end = cal.getTime();
   ServiceRunProvider.InsertRow(myDb, new ServiceRunProvider.ServiceRun(-1, start, end, 4, 1));
   ServiceRunProvider.ServiceRun latest = ServiceRunProvider.LatestRun(myDb);
   assertEquals("id", 2, latest.getId());
   assertEquals("received", 4, latest.getNumReceived());
   assertEquals("triggered", 1, latest.getNumTriggered());
 }
コード例 #5
0
 @Test
 public void ServiceRunsInsertRow() {
   Calendar cal = Calendar.getInstance(Locale.getDefault());
   Date start = cal.getTime();
   cal.add(Calendar.HOUR, 1);
   Date end = cal.getTime();
   ServiceRunProvider.InsertRow(myDb, new ServiceRunProvider.ServiceRun(-1, start, end, 2, 1));
   Cursor c = myDb.rawQuery("select * from serviceruns", null);
   assertEquals("one row expected", 1, c.getCount());
   c.moveToFirst();
   long id = c.getLong(c.getColumnIndexOrThrow(DbContract.ServiceRuns._ID));
   assertEquals("First id equal to 1", 1, id);
   long received =
       c.getLong(c.getColumnIndexOrThrow(DbContract.ServiceRuns.COLUMN_NAME_TOTAL_RECEIVED));
   assertEquals("Expected calls received", 2, received);
   long triggered =
       c.getLong(c.getColumnIndexOrThrow(DbContract.ServiceRuns.COLUMN_NAME_TOTAL_TRIGGERED));
   assertEquals("Expected calls triggered", 1, triggered);
   c.close();
 }