/** {@inheritDoc} */ @Override protected String keystorePath() { return IgniteUtils.resolveIgnitePath("modules/indexing/src/test/resources/tde.jks").getAbsolutePath(); } }
/** * Gets all direct marshallable classes. * First classes will be classes from {@code classesOrder} with same order * as ordered values. Other classes will be at the end and ordered by name * (with package prefix). * That orders need for saving {@code directType} value. * * @return Classes. * @throws Exception In case of error. */ private Collection<Class<? extends Message>> classes() throws Exception { Collection<Class<? extends Message>> col = new TreeSet<>( new Comparator<Class<? extends Message>>() { @Override public int compare(Class<? extends Message> c1, Class<? extends Message> c2) { return c1.getName().compareTo(c2.getName()); } }); ClassLoader ldr = getClass().getClassLoader(); for (URL url : IgniteUtils.classLoaderUrls(ldr)) { File file = new File(url.toURI()); int prefixLen = file.getPath().length() + 1; processFile(file, ldr, prefixLen, col); } return col; }
return Collections.emptyList(); int[] batchSizes = calculateOptimalBatchSizes(parallelismLvl, srcDatas.size()); error = addSuppressed(error, err); error = addSuppressed(error, e.getCause()); error = addSuppressed(error, e);
List<InetAddress> locAddrs = new ArrayList<>(); for (NetworkInterface itf : asIterable(NetworkInterface.getNetworkInterfaces())) { for (InetAddress addr : asIterable(itf.getInetAddresses())) { if (!addr.isLinkLocalAddress()) locAddrs.add(addr); locAddrs = filterReachable(locAddrs); addresses(addr, addrs, hostNames, allHostNames); addresses(locAddr, addrs, hostNames, allHostNames);
new BinaryContext(metaHnd, ctx.config(), ctx.log(BinaryContext.class)); IgniteUtils.invoke(BinaryMarshaller.class, bMarsh0, "setBinaryContext", binaryCtx, ctx.config());
/** * Check that field exist. * * @param obj Object. * @param fieldName Field name. * @return Boolean flag. */ public static boolean hasField(Object obj, String fieldName){ try { field(obj, fieldName); return true; }catch (IgniteException e){ return false; } } /**
/** * Execute operation on data in parallel. * * @param executorSvc Service for parallel execution. * @param srcDatas List of data for parallelization. * @param operation Logic for execution of on each item of data. * @param <T> Type of data. * @throws IgniteCheckedException if parallel execution was failed. */ public static <T, R> Collection<R> doInParallel( ExecutorService executorSvc, Collection<T> srcDatas, IgniteThrowableConsumer<T, R> operation ) throws IgniteCheckedException, IgniteInterruptedCheckedException { return doInParallel(srcDatas.size(), executorSvc, srcDatas, operation); }
/** * Joins given collection of runnables. * * @param ws Collection of workers to join. * @param log The logger to possible exceptions. * @return {@code true} if none of the worker have been interrupted, * {@code false} if at least one was interrupted. */ public static boolean join(Iterable<? extends GridWorker> ws, IgniteLogger log) { boolean retval = true; if (ws != null) for (GridWorker w : ws) if (!join(w, log)) retval = false; return retval; }
/** * Quietly closes given resource ignoring possible checked exceptions. * * @param rsrc Resource to close. If it's {@code null} - it's no-op. */ public static void closeQuiet(@Nullable SelectionKey rsrc) { if (rsrc != null) // This apply will automatically deregister the selection key as well. closeQuiet(rsrc.channel()); }
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); SHARED.set(false); System.clearProperty(IGNITE_MARSHALLER_WHITELIST); System.clearProperty(IGNITE_MARSHALLER_BLACKLIST); IgniteUtils.clearClassCache(); }
/** * Test optimal splitting on batch sizes. */ @Test public void testOptimalBatchSize() { assertArrayEquals(new int[]{1}, IgniteUtils.calculateOptimalBatchSizes(1, 1)); assertArrayEquals(new int[]{2}, IgniteUtils.calculateOptimalBatchSizes(1, 2)); assertArrayEquals(new int[]{1, 1, 1, 1}, IgniteUtils.calculateOptimalBatchSizes(6, 4)); assertArrayEquals(new int[]{1}, IgniteUtils.calculateOptimalBatchSizes(4, 1)); assertArrayEquals(new int[]{1, 1}, IgniteUtils.calculateOptimalBatchSizes(4, 2)); assertArrayEquals(new int[]{1, 1, 1}, IgniteUtils.calculateOptimalBatchSizes(4, 3)); assertArrayEquals(new int[]{1, 1, 1, 1}, IgniteUtils.calculateOptimalBatchSizes(4, 4)); assertArrayEquals(new int[]{2, 1, 1, 1}, IgniteUtils.calculateOptimalBatchSizes(4, 5)); assertArrayEquals(new int[]{2, 2, 1, 1}, IgniteUtils.calculateOptimalBatchSizes(4, 6)); assertArrayEquals(new int[]{2, 2, 2, 1}, IgniteUtils.calculateOptimalBatchSizes(4, 7)); assertArrayEquals(new int[]{2, 2, 2, 2}, IgniteUtils.calculateOptimalBatchSizes(4, 8)); assertArrayEquals(new int[]{3, 2, 2, 2}, IgniteUtils.calculateOptimalBatchSizes(4, 9)); assertArrayEquals(new int[]{3, 3, 2, 2}, IgniteUtils.calculateOptimalBatchSizes(4, 10)); }
/** * Simple test of address list filtering. * @throws Exception If failed. */ @Test public void testResolveReachableOneAddress() throws Exception { InetAddress addr = InetAddress.getByAddress(new byte[] {127, 0, 0, 1} ); List <InetAddress> filtered = IgniteUtils.filterReachable(Collections.singletonList(addr)); assertEquals(1, filtered.size()); assertEquals(addr, filtered.get(0)); }
/** * Create instance of {@link BinaryMarshaller} suitable for use * without starting a grid upon given {@link IgniteConfiguration}. * * @return Binary marshaller. * @throws IgniteCheckedException if failed. */ protected BinaryMarshaller createStandaloneBinaryMarshaller(IgniteConfiguration cfg) throws IgniteCheckedException { BinaryMarshaller marsh = new BinaryMarshaller(); BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), cfg, new NullLogger()); marsh.setContext(new MarshallerContextTestImpl()); IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, cfg); return marsh; }
/** * Template method to test parallel execution * @param executorService ExecutorService. * @param size Size. * @param parallelism Parallelism. * @throws IgniteCheckedException Exception. */ private void testOrder(ExecutorService executorService, int size, int parallelism) throws IgniteCheckedException { List<Integer> list = new ArrayList<>(); for(int i = 0; i < size; i++) list.add(i); Collection<Integer> results = IgniteUtils.doInParallel( parallelism, executorService, list, i -> i * 2 ); assertEquals(list.size(), results.size()); final int[] i = {0}; results.forEach(new Consumer<Integer>() { @Override public void accept(Integer integer) { assertEquals(2 * list.get(i[0]), integer.intValue()); i[0]++; } }); }
List<InetAddress> locAddrs = new ArrayList<>(); for (NetworkInterface itf : asIterable(NetworkInterface.getNetworkInterfaces())) { for (InetAddress addr : asIterable(itf.getInetAddresses())) { if (!addr.isLinkLocalAddress()) locAddrs.add(addr); locAddrs = filterReachable(locAddrs); addresses(addr, addrs, hostNames, allHostNames); addresses(locAddr, addrs, hostNames, allHostNames);
/** * Waits for completion of a given threads. If thread is {@code null} then * this method returns immediately returning {@code true} * * @param workers Thread to join. * @param log Logger for logging errors. * @return {@code true} if thread has finished, {@code false} otherwise. */ public static boolean joinThreads(Iterable<? extends Thread> workers, @Nullable IgniteLogger log) { boolean retval = true; if (workers != null) for (Thread worker : workers) if (!join(worker, log)) retval = false; return retval; }
/** * Load properties from the url. * * @param expLoaded Expected number of loaded properties. * @param url URL to load properties from. * @return Loaded properties. * @throws IOException In case of IO exception. */ private Properties loadProperties(int expLoaded, URL url) throws IOException { InputStream in = url.openStream(); Properties props = new Properties(); assertEquals(0, props.size()); props.load(in); assertEquals(expLoaded, props.size()); IgniteUtils.closeQuiet(in); return props; }