<commit_before>package org.sagebionetworks.audit.worker;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sagebionetworks.audit.dao.AccessRecordDAO;
import org.sagebionetworks.repo.model.audit.AccessRecord;
import org.sagebionetworks.repo.model.dao.semaphore.SemaphoreDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.S3ObjectSummary;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:audit-dao.spb.xml", "classpath:dao-beans.spb.xml" })
public class MergeWorkerTest {
	
	private long MAX_WAIT = 1000*208;
	private final String SEMAPHORE_KEY = "auditMergeWorkerFactory";

	@Autowired
	private AccessRecordDAO accessRecordDAO;
	
	@Autowired
	private SemaphoreDao semaphoreDAO;
	
	private String lockToken;
	
	@Before
	public void before() {
		// Prevent the main scheduler from running another instance of the MergeWorker
		lockToken = semaphoreDAO.attemptToAcquireLock(SEMAPHORE_KEY, MAX_WAIT);
		if (lockToken == null) {
			fail();
		}
	}
	
	@After
	public void after(){
		// Delete all data created by this test.
		accessRecordDAO.deleteAllStackInstanceBatches();
		
		semaphoreDAO.releaseLock(SEMAPHORE_KEY, lockToken);
	}
	
	@Test
	public void testIntegration() throws IOException{<commit_msg>Keep trying to get lock<commit_after>package org.sagebionetworks.audit.worker;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sagebionetworks.audit.dao.AccessRecordDAO;
import org.sagebionetworks.repo.model.audit.AccessRecord;
import org.sagebionetworks.repo.model.dao.semaphore.SemaphoreDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.S3ObjectSummary;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:audit-dao.spb.xml", "classpath:dao-beans.spb.xml" })
public class MergeWorkerTest {
	
	private long MAX_WAIT = 1000*208;
	private final String SEMAPHORE_KEY = "auditMergeWorkerFactory";

	@Autowired
	private AccessRecordDAO accessRecordDAO;
	
	@Autowired
	private SemaphoreDao semaphoreDAO;
	
	private String lockToken;
	
	@Before
	public void before() {
		// Prevent the main scheduler from running another instance of the MergeWorker
		long start = System.currentTimeMillis();
		while (lockToken == null) {
			lockToken = semaphoreDAO.attemptToAcquireLock(SEMAPHORE_KEY, MAX_WAIT);
			long elapse = System.currentTimeMillis() - start;
			assertTrue("Timed out waiting for merge worker to acquire lock", elapse < MAX_WAIT);
		}
	}
	
	@After
	public void after(){
		// Delete all data created by this test.
		accessRecordDAO.deleteAllStackInstanceBatches();
		
		semaphoreDAO.releaseLock(SEMAPHORE_KEY, lockToken);
	}
	
	@Test
	public void testIntegration() throws IOException{
{'fraction_non_alphanumeric': 0.09490379615184608, 'fraction_numerical': 0.006760270410816433, 'mean_word_length': 5.713787085514834, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '683520', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1228, 'n_words': 251}