/** * Constructs unique affinity UUID based on affinity key. * * @param affKey Affinity key to use for collocation. */ public AffinityUuid(Object affKey) { super(IgniteUuid.randomUuid(), affKey); }
/** * @param timeout Timeout for this object. */ protected GridTimeoutObjectAdapter(long timeout) { this(IgniteUuid.randomUuid(), timeout); }
/** * Add surrogate IDs to provided collection potentially creating them on demand. * * @param col Collection. */ @SuppressWarnings("ManualArrayToCollectionCopy") public void addSurrogateIds(Collection<IgniteUuid> col) { if (surrogateIds == null) { surrogateIds = new IgniteUuid[ids.length]; for (int i = lastExistingIdx + 1; i < surrogateIds.length; i++) surrogateIds[i] = IgniteUuid.randomUuid(); } for (int i = lastExistingIdx + 1; i < surrogateIds.length; i++) col.add(surrogateIds[i]); }
/** * @param igniteInstanceName Ignite instance name. * @param name Worker name. * @param log Log. */ protected AsyncDeleteWorker(@Nullable String igniteInstanceName, String name, IgniteLogger log) { super(igniteInstanceName, name, log); stopInfo = IgfsUtils.createDirectory(IgniteUuid.randomUuid()); }
/** * Create event with given parameters. * * @param nid Node where events were lost. */ public VisorGridEventsLost(UUID nid) { super(0, IgniteUuid.randomUuid(), "EVT_VISOR_EVENTS_LOST", nid, U.currentTimeMillis(), "Some Visor events were lost and Visor may show inconsistent results. " + "Configure your grid to disable not important events.", ""); }
/** * Opens file in the browser with given HTML content. * * @param html HTML content. * @throws IOException Thrown in case of any errors. */ private static void openHtmlFile(String html) throws IOException { File temp = File.createTempFile(IgniteUuid.randomUuid().toString(), ".html"); BufferedWriter bw = new BufferedWriter(new FileWriter(temp)); bw.write(html); bw.close(); Desktop.getDesktop().browse(temp.toURI()); }
/** */ public GridTestJobContext() { jobId = IgniteUuid.randomUuid(); }
/** * JUnit. */ @Test public void testGridUuidPerformance() { long start = System.currentTimeMillis(); for (int i = 0; i < NUM; i++) UUID.randomUUID(); long dur1 = System.currentTimeMillis() - start; start = System.currentTimeMillis(); for (int i = 0; i < NUM; i++) IgniteUuid.randomUuid(); long dur2 = System.currentTimeMillis() - start; if (dur2 == 0) dur2 = 1; System.out.println("Creation: UUID=" + dur1 + "ms, GridUuid=" + dur2 + "ms, " + (dur1 / dur2) + "x faster."); }
@Nullable @Override public Object call() throws IgniteCheckedException { testSerialization(IgfsUtils.createDirectory(IgniteUuid.randomUuid())); return null; } }, 20);
/** * @throws Exception In case of an error. */ @Test public void testClusterSingletonWithOldTop() throws Exception { ServiceConfiguration cfg = new ServiceConfiguration(); cfg.setName(TEST_SERVICE_NAME); cfg.setTotalCount(1); IgniteUuid srvcId = IgniteUuid.randomUuid(); TreeMap<UUID, Integer> oldTop = new TreeMap<>(); ClusterNode randomNode = nodes.get(new Random().nextInt(nodes.size())); oldTop.put(randomNode.id(), 1); runTestReassignFunction(srvcId, cfg, oldTop); }
/** * @throws Exception If failed. */ @Test public void testIgniteUuid() throws Exception { IgniteUuid uuid = IgniteUuid.randomUuid(); assertEquals(uuid, marshalUnmarshal(uuid)); }
/** * @param ctx Context. * @param cfg0 Template configuration. * @return Request to add template. */ static DynamicCacheChangeRequest addTemplateRequest(GridKernalContext ctx, CacheConfiguration<?, ?> cfg0) { CacheConfiguration<?, ?> cfg = new CacheConfiguration<>(cfg0); DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(UUID.randomUUID(), cfg.getName(), ctx.localNodeId()); req.template(true); req.startCacheConfiguration(cfg); req.schema(new QuerySchema(cfg.getQueryEntities())); req.deploymentId(IgniteUuid.randomUuid()); return req; }
/** * @throws Exception In case of an error. */ @Test public void testNodeSingletonWithOldTop() throws Exception { ServiceConfiguration cfg = new ServiceConfiguration(); cfg.setName(TEST_SERVICE_NAME); cfg.setMaxPerNodeCount(1); IgniteUuid srvcId = IgniteUuid.randomUuid(); TreeMap<UUID, Integer> oldTop = new TreeMap<>(); for (ClusterNode node : nodes) oldTop.put(node.id(), 1); runTestReassignFunction(srvcId, cfg, oldTop); }
/** * @throws Exception In case of an error. */ @Test public void testNodeSingleton() throws Exception { ServiceConfiguration cfg = new ServiceConfiguration(); cfg.setName(TEST_SERVICE_NAME); cfg.setMaxPerNodeCount(1); runTestReassignFunction(IgniteUuid.randomUuid(), cfg, null); }
/** * @throws Exception In case of an error. */ @Test public void testClusterSingleton() throws Exception { ServiceConfiguration cfg = new ServiceConfiguration(); cfg.setName(TEST_SERVICE_NAME); cfg.setTotalCount(1); runTestReassignFunction(IgniteUuid.randomUuid(), cfg, null); }
/** * @throws Exception If failed. */ @SuppressWarnings({"ObjectEquality"}) @Test public void testSingleNodeZeroWeight() throws Exception { GridTestNode node = (GridTestNode)getSpiContext().nodes().iterator().next(); node.addAttribute("load", 0d); List<ClusterNode> nodes = Collections.singletonList((ClusterNode)node); ComputeTaskSession ses = new GridTestTaskSession(IgniteUuid.randomUuid()); GridTestNode pick1 = (GridTestNode)getSpi().getBalancedNode(ses, nodes, new GridTestJob()); pick1.setAttribute("used", true); assert nodes.contains(pick1); // Verify that same instance is returned every time. ClusterNode pick2 = getSpi().getBalancedNode(ses, nodes, new GridTestJob()); assert pick1 == pick2; }
/** * @throws Exception In case of an error. */ @Test public void testCustomConfiguration() throws Exception { ServiceConfiguration cfg = new ServiceConfiguration(); cfg.setName(TEST_SERVICE_NAME); cfg.setMaxPerNodeCount(3); cfg.setTotalCount(10); runTestReassignFunction(IgniteUuid.randomUuid(), cfg, null); }
/** * Check distribution for integer overflow. * * @throws Exception If failed. */ public void checkIntOverflowDistribution(int partCnt) throws Exception { IgniteUuid fileId = IgniteUuid.randomUuid(); IgfsGroupDataBlocksKeyMapper mapper = new IgfsGroupDataBlocksKeyMapper(1); int part1 = partition(mapper, fileId, Integer.MAX_VALUE - 1, partCnt); int part2 = partition(mapper, fileId, Integer.MAX_VALUE, partCnt); int part3 = partition(mapper, fileId, (long)Integer.MAX_VALUE + 1, partCnt); assert checkPartition(part1, part2, partCnt) : "[fileId = " + fileId + "part1=" + part1 + ", part2=" + part2 + ", partCnt=" + partCnt + ']'; assert checkPartition(part2, part3, partCnt) : "[fileId = " + fileId + "part1=" + part2 + ", part3=" + part3 + ", partCnt=" + partCnt + ']'; }
/** * @throws Exception If test failed. */ @Test public void testMultipleTaskSessions() throws Exception { ComputeTaskSession ses1 = new GridTestTaskSession(IgniteUuid.randomUuid()); ComputeTaskSession ses2 = new GridTestTaskSession(IgniteUuid.randomUuid()); List<ClusterNode> allNodes = (List<ClusterNode>)getSpiContext().nodes(); List<UUID> orderedNodes = getSpi().getNodeIds(ses1); assertEquals("Balancer doesn't use all available nodes", orderedNodes.size(), allNodes.size()); checkCyclicBalancing(getSpi(), allNodes, orderedNodes, ses1, ses2); getSpiContext().triggerEvent(new TaskEvent( null, null, EVT_TASK_FINISHED, ses1.getId(), null, null, false, null)); getSpiContext().triggerEvent(new TaskEvent( null, null, EVT_TASK_FAILED, ses2.getId(), null, null, false, null)); }
/** * @throws Exception If failed. */ @Test public void testAddUpdateAdd() throws Exception { IgfsFileMap map = new IgfsFileMap(); IgniteUuid affKey = IgniteUuid.randomUuid(); map.addRange(new IgfsFileAffinityRange(0, 9, affKey)); map.updateRangeStatus(new IgfsFileAffinityRange(0, 9, affKey), RANGE_STATUS_MOVING); map.addRange(new IgfsFileAffinityRange(10, 19, affKey)); List<IgfsFileAffinityRange> ranges = map.ranges(); assertEquals(2, ranges.size()); assertEquals(RANGE_STATUS_MOVING, ranges.get(0).status()); assertTrue(ranges.get(0).regionEqual(new IgfsFileAffinityRange(0, 9, affKey))); assertEquals(RANGE_STATUS_INITIAL, ranges.get(1).status()); assertTrue(ranges.get(1).regionEqual(new IgfsFileAffinityRange(10, 19, affKey))); }