### Question:
JobPicker { public boolean lockObj( JobDefinition jd, String clusterID, String threadID ) { String objectName = jd.getActualObjectName(); ObjectDefinition od = jd.getObjectDefinition(); if ( template.queryForList( FIND_LOCK, od.getNameSpace(), objectName, od.getUsageCode(), od.getFileType(), clusterID, threadID,jd.getWfType() ).size() > 0 ) { return extendLock( jd, clusterID, threadID ); } else { unlockWorker( clusterID, threadID ); int updated = template.update( LOCK_QUERY, od.getNameSpace(), objectName, od.getUsageCode(), od.getFileType(), clusterID, threadID, jd.getWfType() ); return updated == 1; } }  boolean lockObj( JobDefinition jd, String clusterID, String threadID ); void unlockWorker( String clusterID, String threadID ); boolean extendLock( JobDefinition jd, String clusterID, String workerID ); static final String FIND_UNLOCKED_JOB_QUERY; static final String FIND_UNLOCKED_STATS_JOB_QUERY; }### Answer:
@Test @Transactional public void testLockObjNewLock() { String workerID = String.valueOf(Thread.currentThread().getId()); assertTrue(jp.lockObj(new JobDefinition(1L,"A","B","C","D", "","","",""), "C111", workerID)); assertTrue(jp.lockObj(new JobDefinition(2L,"A","B","C","D", "","","",""), "C111", workerID)); assertFalse(jp.lockObj(new JobDefinition(3L,"A","B","C","D", "","","",""), "C222", workerID)); assertTrue(jp.lockObj(new JobDefinition(4L,"A2","B2","C2","D2", "","","",""), "C111", workerID)); assertFalse(jp.lockObj(new JobDefinition(5L,"A2","B2","C2","D2", "","","",""), "C111","2")); }
@Test @Transactional public void testLockSawCompactionObj() { String correlation = "{\n" + " \"businessObject\": {\n" + " \"late_reporting_for\":\"ABC\"\n" + " }\n" + "}"; assertTrue("First Lock", jp.lockObj(new JobDefinition(1L, "SAW", "ABC", "PRC","BZ", "","","",""),"C111", "1")); assertFalse(jp.lockObj(new JobDefinition(2L, "SAW", "ABC_COMPACTION", "PRC","BZ", "",correlation,"",""),"C222", "1")); assertTrue("First Lock", jp.lockObj(new JobDefinition(3L, "SAW", "ABC_COMPACTION", "PRC-2","BZ","",correlation,"",""),"C111", "1")); assertFalse("First Lock", jp.lockObj(new JobDefinition(4L,"SAW", "ABC_COMPACTION", "PRC-2","BZ", "",correlation,"",""),"C222", "1")); assertFalse(jp.lockObj(new JobDefinition(5L, "SAW", "ABC", "PRC-2","BZ", "",correlation,"",""),"C222", "1")); }