package used;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.*;
public class ExecutorServiceExample {
public static Map<String, String> adresWhisW = new ConcurrentHashMap();
CountDownLatch []cdl = new CountDownLatch[24];
public static void main(String args[]) {
Set<String> ss=new HashSet();
ss.add("вася");
ss.add("петя");
new ExecutorServiceExample(ss);
System.out.println(1);
for (Map.Entry<String, String> entry : adresWhisW.entrySet()) {
System.out.println(2);
System.out.println(entry.getKey() + " " + entry.getValue());
}
}
ExecutorServiceExample(Set<String> ss) {
for (int tr = 1; tr < 24; tr++) {
cdl[tr] = new CountDownLatch(24);
}
ExecutorService executor;
executor = Executors.newFixedThreadPool(24);
for (int tr = 1; tr < 24; tr++) {
executor.execute(new MyThread(ss,adresWhisW));
}
for (int tr = 1; tr < 24; tr++) {
try {
cdl[tr].await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
executor.shutdown();
}
public class MyThread implements Runnable {
private Set<String> strSet;
private Map<String, String> outputMap;
public MyThread(Set<String> strSet, Map<String, String> outputMap) {
this.strSet = strSet;
this.outputMap = outputMap;
}
@Override
public void run() {
for (String str : strSet) {
str=str+str;
outputMap.put(str, str);
}
}
}
}
@Test
public void testaddAccount() throws SQLException {
String currUserEmail = "mail";
String account = "account";
String info = "info";
PreparedStatement statementMock = mock(PreparedStatement.class);
Connection connectionMock = mock(Connection.class);
ConnectionPool connectionPoolMock = mock(ConnectionPool.class);
when(connectionPoolMock.getConnection()).thenReturn(connectionMock);
when(connectionMock.prepareStatement(SQL_ADD_CARD)).thenReturn(statementMock);
PowerMockito.mockStatic(ConnectionPool.class);
when(ConnectionPool.getInstance()).thenReturn(connectionPoolMock);
assertEquals(true, factoryDAO.getAccountDao().addAccount(currUserEmail, account, info));
verify(statementMock).setString(1, currUserEmail);
verify(statementMock).setString(2, account);
verify(statementMock).setString(3, info);
}