@Test public void testNetworkConfig() { NetworkConfig networkConfig = config.getNetworkConfig(); assertNotNull(networkConfig); assertEquals(5700, networkConfig.getPort()); assertFalse(networkConfig.isPortAutoIncrement()); final Collection<String> allowedPorts = networkConfig.getOutboundPortDefinitions(); assertEquals(2, allowedPorts.size()); Iterator portIter = allowedPorts.iterator(); assertEquals("35000-35100", portIter.next()); assertEquals("36000,36100", portIter.next()); assertFalse(networkConfig.getJoin().getMulticastConfig().isEnabled()); assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeoutSeconds(), 8); assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeToLive(), 16); assertFalse(networkConfig.getInterfaces().isEnabled()); assertEquals(1, networkConfig.getInterfaces().getInterfaces().size()); assertEquals("10.10.1.*", networkConfig.getInterfaces().getInterfaces().iterator().next()); TcpIpConfig tcp = networkConfig.getJoin().getTcpIpConfig(); assertNotNull(tcp); assertTrue(tcp.isEnabled()); assertTrue(networkConfig.getSymmetricEncryptionConfig().isEnabled()); final List<String> members = tcp.getMembers(); assertEquals(members.toString(), 2, members.size()); assertEquals("127.0.0.1:5700", members.get(0)); assertEquals("127.0.0.1:5701", members.get(1)); assertEquals("127.0.0.1:5700", tcp.getRequiredMember()); AwsConfig aws = networkConfig.getJoin().getAwsConfig(); assertFalse(aws.isEnabled()); assertEquals("sample-access-key", aws.getAccessKey()); assertEquals("sample-secret-key", aws.getSecretKey()); assertEquals("sample-region", aws.getRegion()); assertEquals("sample-group", aws.getSecurityGroupName()); assertEquals("sample-tag-key", aws.getTagKey()); assertEquals("sample-tag-value", aws.getTagValue()); }
public void run() { while (true) { TransactionContext context = hazelcast.newTransactionContext(); context.beginTransaction(); Set<Integer> setAllInvolvedPMs = new HashSet<Integer>(9); try { Order order = qOrders.take(); countOrdersProcessed.incrementAndGet(); List<Integer> lsAccounts = order.lsAccounts; int accountQuantity = order.quantity / lsAccounts.size(); // for (Integer account : lsAccounts) { // String key = account + "," + order.instrumentId; // updatePosition(key, order, account, accountQuantity); // } String key = order.portfolioManagerId + "," + order.instrumentId; updatePosition(key, order, order.portfolioManagerId, order.quantity); context.commitTransaction(); // setAllInvolvedPMs.addAll(lsAccounts); setAllInvolvedPMs.add(order.portfolioManagerId); for (Integer involvedPM : setAllInvolvedPMs) { mapNewOrders.put(involvedPM, order.instrumentId); } } catch (Throwable t) { t.printStackTrace(); context.rollbackTransaction(); } } }
public void interceptAfterRemove(String mapName, Object value) { List<MapInterceptor> interceptors = getMapContainer(mapName).getInterceptors(); if (!interceptors.isEmpty()) { for (MapInterceptor interceptor : interceptors) { value = toObject(value); interceptor.afterRemove(value); } } }
public void interceptAfterPut(String mapName, Object newValue) { List<MapInterceptor> interceptors = getMapContainer(mapName).getInterceptors(); if (!interceptors.isEmpty()) { newValue = toObject(newValue); for (MapInterceptor interceptor : interceptors) { interceptor.afterPut(newValue); } } }
@Test public void testRetainAllList() throws IOException { final int maxItems = 181; final IQueue q = client.getQueue(randomString()); List retain = new LinkedList(); for (int i = 0; i < maxItems; i++) { q.add(i); retain.add(i); } assertFalse(q.retainAll(retain)); assertEquals(maxItems, q.size()); }
@Test public void testRemoveList() throws IOException { final int maxItems = 131; final IQueue q = client.getQueue(randomString()); List removeList = new LinkedList(); for (int i = 0; i < maxItems; i++) { q.add(i); removeList.add(i); } assertTrue(q.removeAll(removeList)); assertEquals(0, q.size()); }
public Object interceptRemove(String mapName, Object value) { List<MapInterceptor> interceptors = getMapContainer(mapName).getInterceptors(); Object result = null; if (!interceptors.isEmpty()) { result = toObject(value); for (MapInterceptor interceptor : interceptors) { Object temp = interceptor.interceptRemove(result); if (temp != null) { result = temp; } } } return result == null ? value : result; }
@Test public void testContainsAll() { final int maxItems = 11; final IQueue q = client.getQueue(randomString()); List trueList = new ArrayList(); List falseList = new ArrayList(); for (int i = 0; i < maxItems; i++) { q.offer(i); trueList.add(i); falseList.add(i + 1); } assertTrue(q.containsAll(trueList)); assertFalse(q.containsAll(falseList)); }
@Test public void testConfigListeners() { assertNotNull(membershipListener); List<ListenerConfig> list = config.getListenerConfigs(); assertEquals(2, list.size()); for (ListenerConfig lc : list) { if (lc.getClassName() != null) { assertNull(lc.getImplementation()); assertEquals(DummyMembershipListener.class.getName(), lc.getClassName()); } else { assertNotNull(lc.getImplementation()); assertEquals(membershipListener, lc.getImplementation()); } } }
public Object interceptPut(String mapName, Object oldValue, Object newValue) { List<MapInterceptor> interceptors = getMapContainer(mapName).getInterceptors(); Object result = null; if (!interceptors.isEmpty()) { result = toObject(newValue); oldValue = toObject(oldValue); for (MapInterceptor interceptor : interceptors) { Object temp = interceptor.interceptPut(oldValue, result); if (temp != null) { result = temp; } } } return result == null ? newValue : result; }
@Test public void testDrain() { final int maxItems = 12; final IQueue q = client.getQueue(randomString()); List offeredList = new LinkedList(); for (int i = 0; i < maxItems; i++) { q.offer(i); offeredList.add(i); } List drainedList = new LinkedList(); int totalDrained = q.drainTo(drainedList); assertEquals(maxItems, totalDrained); assertEquals(offeredList, drainedList); }
public QueryResult queryOnPartition(String mapName, Predicate predicate, int partitionId) { final QueryResult result = new QueryResult(); List<QueryEntry> list = new LinkedList<QueryEntry>(); PartitionContainer container = getPartitionContainer(partitionId); RecordStore recordStore = container.getRecordStore(mapName); Map<Data, Record> records = recordStore.getReadonlyRecordMap(); SerializationService serializationService = nodeEngine.getSerializationService(); final PagingPredicate pagingPredicate = predicate instanceof PagingPredicate ? (PagingPredicate) predicate : null; Comparator<Map.Entry> wrapperComparator = SortingUtil.newComparator(pagingPredicate); for (Record record : records.values()) { Data key = record.getKey(); Object value = record.getValue(); if (value == null) { continue; } QueryEntry queryEntry = new QueryEntry(serializationService, key, key, value); if (predicate.apply(queryEntry)) { if (pagingPredicate != null) { Map.Entry anchor = pagingPredicate.getAnchor(); if (anchor != null && SortingUtil.compare( pagingPredicate.getComparator(), pagingPredicate.getIterationType(), anchor, queryEntry) >= 0) { continue; } } list.add(queryEntry); } } if (pagingPredicate != null) { Collections.sort(list, wrapperComparator); if (list.size() > pagingPredicate.getPageSize()) { list = list.subList(0, pagingPredicate.getPageSize()); } } for (QueryEntry entry : list) { result.add( new QueryResultEntryImpl(entry.getKeyData(), entry.getKeyData(), entry.getValueData())); } return result; }
@Test public void testPartialDrain() { final int maxItems = 15; final int itemsToDrain = maxItems / 2; final IQueue q = client.getQueue(randomString()); List expectedList = new LinkedList(); for (int i = 0; i < maxItems; i++) { q.offer(i); if (i < itemsToDrain) { expectedList.add(i); } } List drainedList = new LinkedList(); int totalDrained = q.drainTo(drainedList, itemsToDrain); assertEquals(itemsToDrain, totalDrained); assertEquals(expectedList, drainedList); }
/** Shutdown-related method behaviour when the cluster is running */ @Test public void testShutdownBehaviour() throws Exception { ExecutorService executor = createSingleNodeExecutorService("testShutdownBehaviour"); // Fresh instance, is not shutting down assertFalse(executor.isShutdown()); assertFalse(executor.isTerminated()); executor.shutdown(); assertTrue(executor.isShutdown()); assertTrue(executor.isTerminated()); // shutdownNow() should return an empty list and be ignored List<Runnable> pending = executor.shutdownNow(); assertTrue(pending.isEmpty()); assertTrue(executor.isShutdown()); assertTrue(executor.isTerminated()); // awaitTermination() should return immediately false try { boolean terminated = executor.awaitTermination(60L, TimeUnit.SECONDS); assertFalse(terminated); } catch (InterruptedException ie) { fail("InterruptedException"); } assertTrue(executor.isShutdown()); assertTrue(executor.isTerminated()); }
List<Edge> detectDeadlock() { Collection<Map<String, MapLockState>> collection = (Collection<Map<String, MapLockState>>) callOnAllMembers(new LockInformationCallable()); List<Vertex> graph = new ArrayList<Vertex>(); for (Map<String, MapLockState> mapLockStateMap : collection) { for (MapLockState map : mapLockStateMap.values()) { for (Object key : map.getLockOwners().keySet()) { Vertex owner = new Vertex(map.getLockOwners().get(key)); Vertex requester = new Vertex(map.getLockRequested().get(key)); int index = graph.indexOf(owner); if (index >= 0) { owner = graph.get(index); } else { graph.add(owner); } index = graph.indexOf(requester); if (index >= 0) { requester = graph.get(index); } else { graph.add(requester); } Edge edge = new Edge(); edge.from = requester; edge.to = owner; edge.key = key; edge.mapName = map.getMapName(); edge.globalLock = map.isGlobalLock(); owner.addIncoming(edge); requester.addOutgoing(edge); } } } List<Edge> list = new ArrayList<Edge>(); if (graph != null && graph.size() > 0) { try { graph.get(0).visit(list); } catch (RuntimeException e) { } } return list; }
@Override public List<String> jobIds() { List<String> ret = new ArrayList<>(); for (Job j : this.jobs) ret.add(j.getWorkerId()); return ret; }