test_class.file: usage/src/test/java/com/cloud/usage/UsageSanityCheckerTest.java
test_class.identifier: UsageSanityCheckerTest
test_class.superclass: extends TestCase
test_case.body: @Test
      public void testCheckItemCountByPstmt() throws SQLException {
          // Prepare
          // Mock dependencies to exclude from the test
          String sqlTemplate1 = "SELECT * FROM mytable1";
          String sqlTemplate2 = "SELECT * FROM mytable2";
  
          Connection conn = Mockito.mock(Connection.class);
          PreparedStatement pstmt = Mockito.mock(PreparedStatement.class);
          ResultSet rs = Mockito.mock(ResultSet.class);
  
          Mockito.when(conn.prepareStatement(sqlTemplate1)).thenReturn(pstmt);
          Mockito.when(conn.prepareStatement(sqlTemplate2)).thenReturn(pstmt);
          Mockito.when(pstmt.executeQuery()).thenReturn(rs, rs);
  
          // First if: true -> 8
          // Second loop: true -> 16
          Mockito.when(rs.next()).thenReturn(true, true);
          Mockito.when(rs.getInt(1)).thenReturn(8, 8, 16, 16);
  
          // Prepare class under test
          UsageSanityChecker checker = new UsageSanityChecker();
          checker.conn = conn;
          checker.reset();
          checker.addCheckCase(sqlTemplate1, "item1");
          checker.addCheckCase(sqlTemplate2, "item2");
  
          // Execute
          checker.checkItemCountByPstmt();
  
          // Verify
          Pattern pattern = Pattern.compile(".*8.*item1.*\n.*16.*item2.*");
          Matcher matcher = pattern.matcher(checker.errors);
          assertTrue("Didn't create complete errors. It should create 2 errors: 8 item1 and 16 item2", matcher.find());
      }
test_case.class_method_signature: UsageSanityCheckerTest.testCheckItemCountByPstmt()
test_case.full_signature: @Test public void testCheckItemCountByPstmt()
test_case.identifier: testCheckItemCountByPstmt
test_case.invocations: mock mock mock thenReturn when prepareStatement thenReturn when prepareStatement thenReturn when executeQuery thenReturn when next thenReturn when getInt reset addCheckCase addCheckCase checkItemCountByPstmt compile matcher assertTrue find
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testCheckItemCountByPstmt()
focal_class.declarator: s_logger = LoggerFactory.getLogger(UsageSanityChecker.class)
focal_class.modifier: protected static final
focal_class.original_string: protected static final Logger s_logger = LoggerFactory.getLogger(UsageSanityChecker.class);
focal_class.type: Logger
focal_class.var_name: s_logger
focal_class.declarator: DEFAULT_AGGREGATION_RANGE = 1440
focal_class.modifier: protected static final
focal_class.original_string: protected static final int DEFAULT_AGGREGATION_RANGE = 1440;
focal_class.type: int
focal_class.var_name: DEFAULT_AGGREGATION_RANGE
focal_class.declarator: errors
focal_class.modifier: protected
focal_class.original_string: protected StringBuilder errors;
focal_class.type: StringBuilder
focal_class.var_name: errors
focal_class.declarator: checkCases
focal_class.modifier: protected
focal_class.original_string: protected List<CheckCase> checkCases;
focal_class.type: List<CheckCase>
focal_class.var_name: checkCases
focal_class.declarator: lastCheckFile = "/usr/local/libexec/sanity-check-last-id"
focal_class.modifier: protected
focal_class.original_string: protected String lastCheckFile = "/usr/local/libexec/sanity-check-last-id";
focal_class.type: String
focal_class.var_name: lastCheckFile
focal_class.declarator: lastCheckId = ""
focal_class.modifier: protected
focal_class.original_string: protected String lastCheckId = "";
focal_class.type: String
focal_class.var_name: lastCheckId
focal_class.declarator: lastId = -1
focal_class.modifier: protected
focal_class.original_string: protected int lastId = -1;
focal_class.type: int
focal_class.var_name: lastId
focal_class.declarator: maxId = -1
focal_class.modifier: protected
focal_class.original_string: protected int maxId = -1;
focal_class.type: int
focal_class.var_name: maxId
focal_class.declarator: conn
focal_class.modifier: protected
focal_class.original_string: protected Connection conn;
focal_class.type: Connection
focal_class.var_name: conn
focal_class.file: usage/src/main/java/com/cloud/usage/UsageSanityChecker.java
focal_class.identifier: UsageSanityChecker
focal_class.class_method_signature: UsageSanityChecker.reset()
focal_class.full_signature: protected void reset()
focal_class.identifier: reset
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void reset()
focal_class.class_method_signature: UsageSanityChecker.checkItemCountByPstmt()
focal_class.full_signature: protected boolean checkItemCountByPstmt()
focal_class.identifier: checkItemCountByPstmt
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean checkItemCountByPstmt()
focal_class.class_method_signature: UsageSanityChecker.checkItemCountByPstmt(CheckCase checkCase)
focal_class.full_signature: protected boolean checkItemCountByPstmt(CheckCase checkCase)
focal_class.identifier: checkItemCountByPstmt
focal_class.modifiers: protected
focal_class.parameters: (CheckCase checkCase)
focal_class.return: boolean
focal_class.signature: boolean checkItemCountByPstmt(CheckCase checkCase)
focal_class.class_method_signature: UsageSanityChecker.checkMaxUsage()
focal_class.full_signature: protected void checkMaxUsage()
focal_class.identifier: checkMaxUsage
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void checkMaxUsage()
focal_class.class_method_signature: UsageSanityChecker.checkVmUsage()
focal_class.full_signature: protected void checkVmUsage()
focal_class.identifier: checkVmUsage
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void checkVmUsage()
focal_class.class_method_signature: UsageSanityChecker.checkVolumeUsage()
focal_class.full_signature: protected void checkVolumeUsage()
focal_class.identifier: checkVolumeUsage
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void checkVolumeUsage()
focal_class.class_method_signature: UsageSanityChecker.checkTemplateISOUsage()
focal_class.full_signature: protected void checkTemplateISOUsage()
focal_class.identifier: checkTemplateISOUsage
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void checkTemplateISOUsage()
focal_class.class_method_signature: UsageSanityChecker.checkSnapshotUsage()
focal_class.full_signature: protected void checkSnapshotUsage()
focal_class.identifier: checkSnapshotUsage
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void checkSnapshotUsage()
focal_class.class_method_signature: UsageSanityChecker.readLastCheckId()
focal_class.full_signature: protected void readLastCheckId()
focal_class.identifier: readLastCheckId
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void readLastCheckId()
focal_class.class_method_signature: UsageSanityChecker.readMaxId()
focal_class.full_signature: protected void readMaxId()
focal_class.identifier: readMaxId
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void readMaxId()
focal_class.class_method_signature: UsageSanityChecker.updateNewMaxId()
focal_class.full_signature: protected void updateNewMaxId()
focal_class.identifier: updateNewMaxId
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void updateNewMaxId()
focal_class.class_method_signature: UsageSanityChecker.runSanityCheck()
focal_class.full_signature: public String runSanityCheck()
focal_class.identifier: runSanityCheck
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String runSanityCheck()
focal_class.class_method_signature: UsageSanityChecker.getConnection()
focal_class.full_signature: protected Connection getConnection()
focal_class.identifier: getConnection
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: Connection
focal_class.signature: Connection getConnection()
focal_class.class_method_signature: UsageSanityChecker.main(String args[])
focal_class.full_signature: public static void main(String args[])
focal_class.identifier: main
focal_class.modifiers: public static
focal_class.parameters: (String args[])
focal_class.return: void
focal_class.signature: void main(String args[])
focal_class.class_method_signature: UsageSanityChecker.addCheckCase(String sqlTemplate, String itemName, String lastCheckId)
focal_class.full_signature: protected void addCheckCase(String sqlTemplate, String itemName, String lastCheckId)
focal_class.identifier: addCheckCase
focal_class.modifiers: protected
focal_class.parameters: (String sqlTemplate, String itemName, String lastCheckId)
focal_class.return: void
focal_class.signature: void addCheckCase(String sqlTemplate, String itemName, String lastCheckId)
focal_class.class_method_signature: UsageSanityChecker.addCheckCase(String sqlTemplate, String itemName)
focal_class.full_signature: protected void addCheckCase(String sqlTemplate, String itemName)
focal_class.identifier: addCheckCase
focal_class.modifiers: protected
focal_class.parameters: (String sqlTemplate, String itemName)
focal_class.return: void
focal_class.signature: void addCheckCase(String sqlTemplate, String itemName)
focal_method.body: protected boolean checkItemCountByPstmt() throws SQLException {
          boolean checkOk = true;
  
          for(CheckCase check : checkCases) {
              checkOk &= checkItemCountByPstmt(check);
          }
  
          return checkOk;
      }
focal_method.class_method_signature: UsageSanityChecker.checkItemCountByPstmt()
focal_method.full_signature: protected boolean checkItemCountByPstmt()
focal_method.identifier: checkItemCountByPstmt
focal_method.invocations: checkItemCountByPstmt
focal_method.modifiers: protected
focal_method.parameters: ()
focal_method.return: boolean
focal_method.signature: boolean checkItemCountByPstmt()