<commit_before>package step.grid.filemanager;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.Assert;
import org.junit.Test;

import com.google.common.io.Files;

import step.grid.filemanager.FileProvider.TransportableFile;

public class FIleManagerTest {

	@Test
	public void test() throws IOException {
		FileManagerServer server = new FileManagerServer();
		
		byte[] content = new byte[]{11};
		
		File testFile = new File("./testFileManager");
		testFile.deleteOnExit();
		Files.write(content, testFile);
		
		String id = server.registerFile(testFile);

		final TransportableFile a = server.getTransportableFile(id);
		Assert.assertNotNull(a);
		Assert.assertArrayEquals(content, a.bytes); 

		AtomicInteger remoteCallCounts = new AtomicInteger(0);
		
		FileManagerClient client = new FileManagerClientImpl(new File("."), new FileProvider() {
			@Override
			public TransportableFile getTransportableFile(String fileHandle) throws IOException {
				remoteCallCounts.incrementAndGet();
				return a;
			}
		});
		File clientFile = client.requestFile(id, 1);
		clientFile = client.requestFile(id, 1);
		Assert.assertEquals(1, remoteCallCounts.get());
		clientFile = client.requestFile(id, 2);
		Assert.assertEquals(2, remoteCallCounts.get());
		clientFile = client.requestFile(id, 2);
		Assert.assertEquals(2, remoteCallCounts.get());
		
		byte[] bytes = Files.toByteArray(clientFile);
		Assert.assertArrayEquals(content, bytes); 
		
		clientFile.delete();
	}
	
	@Test
	public void testParallel() throws IOException, InterruptedException {
		AtomicInteger remoteCallCounts = new AtomicInteger(0);
		
		final FileManagerClient client = new FileManagerClientImpl(new File("."), new FileProvider() {
			@Override
			public TransportableFile getTransportableFile(String fileHandle) throws IOException {
				remoteCallCounts.incrementAndGet();
				return new TransportableFile("", false, new byte[]{11});
			}
		});
		
		ExecutorService e = Executors.newFixedThreadPool(5);
		for(int i=0;i<1000;i++) {
			e.submit(()->{
				try {
					File file = client.requestFile("id", 1);
					file.delete();
				} catch(Exception e1) {
					e1.printStackTrace();
				};});
		}
		
		e.shutdown();
		e.awaitTermination(10, TimeUnit.SECONDS);
		Assert.assertEquals(1, remoteCallCounts.get());
		
	}
}
<commit_msg>Fixing JUnit Tests<commit_after>package step.grid.filemanager;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.Assert;
import org.junit.Test;

import com.google.common.io.Files;

import step.commons.helpers.FileHelper;
import step.grid.filemanager.FileProvider.TransportableFile;

public class FIleManagerTest {

	@Test
	public void test() throws IOException {
		FileManagerServer server = new FileManagerServer();
		
		byte[] content = new byte[]{11};
		
		File testFile = new File("./testFileManager");
		testFile.deleteOnExit();
		Files.write(content, testFile);
		
		String id = server.registerFile(testFile);

		final TransportableFile a = server.getTransportableFile(id);
		Assert.assertNotNull(a);
		Assert.assertArrayEquals(content, a.bytes); 

		AtomicInteger remoteCallCounts = new AtomicInteger(0);
		
		File tempDataFolder = new File("./tempDataFolder");
		tempDataFolder.mkdirs();
		
		try {
			FileManagerClient client = new FileManagerClientImpl(tempDataFolder, new FileProvider() {
				@Override
				public TransportableFile getTransportableFile(String fileHandle) throws IOException {
					remoteCallCounts.incrementAndGet();
					return a;
				}
			});
			File clientFile = client.requestFile(id, 1);
			clientFile = client.requestFile(id, 1);
			Assert.assertEquals(1, remoteCallCounts.get());
			clientFile = client.requestFile(id, 2);
			Assert.assertEquals(2, remoteCallCounts.get());
			clientFile = client.requestFile(id, 2);
			Assert.assertEquals(2, remoteCallCounts.get());
			
			byte[] bytes = Files.toByteArray(clientFile);
			Assert.assertArrayEquals(content, bytes); 
			
			clientFile.delete();
		} finally {
			FileHelper.deleteFolder(tempDataFolder);
		}
	}
	
	@Test
	public void testParallel() throws IOException, InterruptedException {
		AtomicInteger remoteCallCounts = new AtomicInteger(0);
		
		File tempDataFolder = new File("./tempDataFolder");
		tempDataFolder.mkdirs();
		try {
			
			final FileManagerClient client = new FileManagerClientImpl(tempDataFolder, new FileProvider() {
				@Override
				public TransportableFile getTransportableFile(String fileHandle) throws IOException {
					remoteCallCounts.incrementAndGet();
					return new TransportableFile("", false, new byte[]{11});
				}
			});
			
			ExecutorService e = Executors.newFixedThreadPool(5);
			for(int i=0;i<1000;i++) {
				e.submit(()->{
					try {
						File file = client.requestFile("id", 1);
						file.delete();
					} catch(Exception e1) {
						e1.printStackTrace();
					};});
			}
			
			e.shutdown();
			e.awaitTermination(10, TimeUnit.SECONDS);
			Assert.assertEquals(1, remoteCallCounts.get());
		} finally {
			FileHelper.deleteFolder(tempDataFolder);
		}
		
	}
}

{'fraction_non_alphanumeric': 0.11514933429291112, 'fraction_numerical': 0.008996041741633681, 'mean_word_length': 3.7716738197424893, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7390229', 'n_tokens_mistral': 1936, 'n_tokens_neox': 1616, 'n_words': 328}