Repository: incubator-ignite Updated Branches: refs/heads/ignite-648-optmarsh e11b6b84f -> 36b9829ac
# ignite-648: opt marshaller experiment Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/36b9829a Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/36b9829a Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/36b9829a Branch: refs/heads/ignite-648-optmarsh Commit: 36b9829ac0ff5ba134fefef5db30a4accc96680a Parents: e11b6b8 Author: Artem Shutak <ashu...@gridgain.com> Authored: Thu May 7 15:45:35 2015 +0300 Committer: Artem Shutak <ashu...@gridgain.com> Committed: Thu May 7 15:45:35 2015 +0300 ---------------------------------------------------------------------- .../cache/GridCacheAbstractFullApiSelfTest.java | 2 +- ...CachePartitionedMultiJvmFullApiSelfTest.java | 11 + .../cache/multijvm/IgniteCacheProcessProxy.java | 500 ------------------- .../cache/multijvm/IgniteExProcessProxy.java | 449 ----------------- .../cache/multijvm/IgniteNodeRunner.java | 154 ------ .../framework/FileMarshallerContext.java | 67 +++ .../framework/IgniteCacheProcessProxy.java | 500 +++++++++++++++++++ .../framework/IgniteExProcessProxy.java | 449 +++++++++++++++++ .../multijvm/framework/IgniteNodeRunner.java | 130 +++++ .../marshaller/MarshallerContextTestImpl.java | 16 +- 10 files changed, 1173 insertions(+), 1105 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36b9829a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java index 801d752..a1180b2 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java @@ -27,7 +27,7 @@ import org.apache.ignite.configuration.*; import org.apache.ignite.events.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.affinity.*; -import org.apache.ignite.internal.processors.cache.multijvm.*; +import org.apache.ignite.internal.processors.cache.multijvm.framework.*; import org.apache.ignite.internal.processors.cache.query.*; import org.apache.ignite.internal.processors.resource.*; import org.apache.ignite.internal.util.lang.*; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36b9829a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCachePartitionedMultiJvmFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCachePartitionedMultiJvmFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCachePartitionedMultiJvmFullApiSelfTest.java index 336949a..5ca3514 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCachePartitionedMultiJvmFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCachePartitionedMultiJvmFullApiSelfTest.java @@ -18,6 +18,7 @@ package org.apache.ignite.internal.processors.cache.multijvm; import org.apache.ignite.internal.processors.cache.distributed.near.*; +import org.apache.ignite.internal.processors.cache.multijvm.framework.*; /** * Multy Jvm tests. @@ -27,4 +28,14 @@ public class GridCachePartitionedMultiJvmFullApiSelfTest extends GridCachePartit protected boolean isMultiJvm() { return true; } + + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + IgniteExProcessProxy.killAll(); + } + + @Override public void testGet() throws Exception { + super.testGet(); // TODO: CODE: implement. + } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36b9829a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteCacheProcessProxy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteCacheProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteCacheProcessProxy.java deleted file mode 100644 index 0b203d9..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteCacheProcessProxy.java +++ /dev/null @@ -1,500 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.cache.multijvm; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.query.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.mxbean.*; -import org.jetbrains.annotations.*; - -import javax.cache.*; -import javax.cache.CacheManager; -import javax.cache.configuration.*; -import javax.cache.expiry.*; -import javax.cache.integration.*; -import javax.cache.processor.*; -import java.util.*; -import java.util.concurrent.locks.*; - -/** - * Ignite cache proxy for ignite instance at another JVM. - */ -public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> { - /** Compute. */ - private final transient IgniteCompute compute; - - /** Cache name. */ - private final String cacheName; - - /** Grid id. */ - private final UUID gridId; - - /** - * @param name Name. - * @param proxy Ignite Process Proxy. - */ - public IgniteCacheProcessProxy(String name, IgniteExProcessProxy proxy) { - cacheName = name; - gridId = proxy.getId(); - - ClusterGroup grp = proxy.localJvmGrid().cluster().forNodeId(proxy.getId()); - - compute = proxy.localJvmGrid().compute(grp); - } - - /** {@inheritDoc} */ - @Override public IgniteCache<K, V> withAsync() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public boolean isAsync() { - return false; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <R> IgniteFuture<R> future() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <C extends Configuration<K, V>> C getConfiguration(Class<C> clazz) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public Entry<K, V> randomEntry() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteCache<K, V> withExpiryPolicy(ExpiryPolicy plc) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteCache<K, V> withSkipStore() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public void loadCache(@Nullable IgniteBiPredicate<K, V> p, @Nullable Object... args) throws CacheException { - // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public void localLoadCache(@Nullable IgniteBiPredicate<K, V> p, @Nullable Object... args) throws CacheException { - // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public V getAndPutIfAbsent(final K key, final V val) throws CacheException { - return (V)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).getAndPutIfAbsent(key, val); - } - }); - } - - /** {@inheritDoc} */ - @Override public Lock lock(K key) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public Lock lockAll(Collection<? extends K> keys) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public boolean isLocalLocked(K key, boolean byCurrThread) { - return false; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <R> QueryCursor<R> query(Query<R> qry) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @SuppressWarnings("unchecked") - @Override public Iterable<Entry<K, V>> localEntries(CachePeekMode... peekModes) throws CacheException { - // TODO: implement. -// return F.first(compute.broadcast(new IgniteClosureX<CachePeekMode[], Iterable>() { -// @Override public Iterable applyx(CachePeekMode... modes) { -// return Ignition.ignite(gridId).cache(cacheName).localEntries(modes); -// } -// }, peekModes)); - - return Collections.emptyList(); - } - - /** {@inheritDoc} */ - @Override public QueryMetrics queryMetrics() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public void localEvict(Collection<? extends K> keys) { - // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public V localPeek(final K key, final CachePeekMode... peekModes) { - return (V)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).localPeek(key, peekModes); - } - }); - } - - /** {@inheritDoc} */ - @Override public void localPromote(Set<? extends K> keys) throws CacheException { - // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public int size(final CachePeekMode... peekModes) throws CacheException { - return (int)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).size(peekModes); - } - }); - } - - /** {@inheritDoc} */ - @Override public int localSize(final CachePeekMode... peekModes) { - return (int)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).localSize(peekModes); - } - }); - } - - /** {@inheritDoc} */ - @Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(Map<? extends K, ? extends EntryProcessor<K, V, T>> map, - Object... args) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public V get(final K key) { - return (V)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).get(key); - } - }); - } - - /** {@inheritDoc} */ - @Override public Map<K, V> getAll(final Set<? extends K> keys) { - return (Map<K, V>)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).getAll(keys); - } - }); - } - - /** {@inheritDoc} */ - @Override public boolean containsKey(final K key) { - return (boolean)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).containsKey(key); - } - }); - } - - /** {@inheritDoc} */ - @Override public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener) { - // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public boolean containsKeys(final Set<? extends K> keys) { - return (boolean)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).containsKeys(keys); - } - }); - } - - /** {@inheritDoc} */ - @Override public void put(final K key, final V val) {; - compute.run(new IgniteRunnable() { - @Override public void run() { - Ignition.ignite(gridId).cache(cacheName).put(key, val); - } - }); - } - - /** {@inheritDoc} */ - @Override public V getAndPut(final K key, final V val) { - return (V)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).getAndPut(key, val); - } - }); - } - - /** {@inheritDoc} */ - @Override public void putAll(final Map<? extends K, ? extends V> map) { - compute.run(new IgniteRunnable() { - @Override public void run() { - Ignition.ignite(gridId).cache(cacheName).putAll(map); - } - }); - } - - /** {@inheritDoc} */ - @Override public boolean putIfAbsent(final K key, final V val) { - return (boolean)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).putIfAbsent(key, val); - } - }); - } - - /** {@inheritDoc} */ - @Override public boolean remove(final K key) { - return (boolean)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).remove(key); - } - }); - } - - /** {@inheritDoc} */ - @Override public boolean remove(final K key, final V oldVal) { - return (boolean)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).remove(key, oldVal); - } - }); - } - - /** {@inheritDoc} */ - @Override public V getAndRemove(final K key) { - return (V)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).getAndRemove(key); - } - }); - } - - /** {@inheritDoc} */ - @Override public boolean replace(final K key, final V oldVal, final V newVal) { - return (boolean)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).replace(key, oldVal, newVal); - } - }); - } - - /** {@inheritDoc} */ - @Override public boolean replace(final K key, final V val) { - return (boolean)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).replace(key, val); - } - }); - } - - /** {@inheritDoc} */ - @Override public V getAndReplace(final K key, final V val) { - return (V)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).getAndReplace(key, val); - } - }); - } - - /** {@inheritDoc} */ - @Override public void removeAll(final Set<? extends K> keys) { - compute.run(new IgniteRunnable() { - @Override public void run() { - Ignition.ignite(gridId).cache(cacheName).removeAll(keys); - } - }); - } - - /** {@inheritDoc} */ - @Override public void removeAll() { - compute.run(new IgniteRunnable() { - @Override public void run() { - Ignition.ignite(gridId).cache(cacheName).removeAll(); - } - }); - } - - /** {@inheritDoc} */ - @Override public void clear() { - compute.run(new IgniteRunnable() { - @Override public void run() { - Ignition.ignite(gridId).cache(cacheName).clear(); - } - }); - } - - /** {@inheritDoc} */ - @Override public void clear(final K key) { - compute.run(new IgniteRunnable() { - @Override public void run() { - Ignition.ignite(gridId).cache(cacheName).clear(key); - } - }); - } - - /** {@inheritDoc} */ - @Override public void clearAll(final Set<? extends K> keys) { - compute.run(new IgniteRunnable() { - @Override public void run() { - Ignition.ignite(gridId).cache(cacheName).clearAll(keys); - } - }); - } - - /** {@inheritDoc} */ - @Override public void localClear(final K key) { - compute.run(new IgniteRunnable() { - @Override public void run() { - Ignition.ignite(gridId).cache(cacheName).localClear(key); - } - }); - } - - /** {@inheritDoc} */ - @Override public void localClearAll(final Set<? extends K> keys) { - compute.run(new IgniteRunnable() { - @Override public void run() { - Ignition.ignite(gridId).cache(cacheName).localClearAll(keys); - } - }); - } - - /** {@inheritDoc} */ - @Override public <T> T invoke(final K key, final EntryProcessor<K, V, T> entryProcessor, final Object... arguments) { - return (T)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).invoke(key, - (EntryProcessor<Object, Object, Object>)entryProcessor, arguments); - } - }); - } - - /** {@inheritDoc} */ - @Override public <T> T invoke(final K key, final CacheEntryProcessor<K, V, T> entryProcessor, final Object... arguments) { - return (T)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).invoke(key, - (CacheEntryProcessor<Object, Object, Object>)entryProcessor, arguments); - } - }); - } - - /** {@inheritDoc} */ - @Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(final Set<? extends K> keys, final EntryProcessor<K, V, T> entryProcessor, - final Object... args) { - return (Map<K, EntryProcessorResult<T>>)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).invokeAll(keys, - (EntryProcessor<Object, Object, Object>)entryProcessor, args); - } - }); - } - - /** {@inheritDoc} */ - @Override public String getName() { - return (String)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).getName(); - } - }); - } - - /** {@inheritDoc} */ - @Override public CacheManager getCacheManager() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public void close() { - compute.run(new IgniteRunnable() { - @Override public void run() { - Ignition.ignite(gridId).cache(cacheName).close(); - } - }); - } - - /** {@inheritDoc} */ - @Override public boolean isClosed() { - return (boolean)compute.call(new IgniteCallable<Object>() { - @Override public Object call() throws Exception { - return Ignition.ignite(gridId).cache(cacheName).isClosed(); - } - }); - } - - /** {@inheritDoc} */ - @Override public <T> T unwrap(Class<T> clazz) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public void registerCacheEntryListener(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) { - // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public void deregisterCacheEntryListener(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) { - // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public Iterator<Entry<K, V>> iterator() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, - CacheEntryProcessor<K, V, T> entryProcessor, Object... args) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteFuture<?> rebalance() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public CacheMetrics metrics() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public CacheMetrics metrics(ClusterGroup grp) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public CacheMetricsMXBean mxBean() { - return null; // TODO: CODE: implement. - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36b9829a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteExProcessProxy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteExProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteExProcessProxy.java deleted file mode 100644 index 469e425..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteExProcessProxy.java +++ /dev/null @@ -1,449 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.cache.multijvm; - -import org.apache.ignite.*; -import org.apache.ignite.cache.affinity.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.*; -import org.apache.ignite.internal.cluster.*; -import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.processors.hadoop.*; -import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.lang.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.plugin.*; -import org.jetbrains.annotations.*; - -import java.util.*; -import java.util.concurrent.*; - -/** - * Ignite proxy for ignite instance at another JVM. - */ -public class IgniteExProcessProxy implements IgniteEx { - /** Grid proxies. */ - private transient static final Map<String, IgniteExProcessProxy> gridProxies = new HashMap<>(); - - /** Jvm process with ignite instance. */ - private transient final GridJavaProcess proc; - - /** Configuration. */ - private transient final IgniteConfiguration cfg; - - /** Local jvm grid. */ - private transient final Ignite locJvmGrid; - - /** Logger. */ - private transient final IgniteLogger log; - - /** Grid id. */ - private final UUID id = UUID.randomUUID(); - - /** Compute. */ - private transient final IgniteCompute compute; - - /** - * @param cfg Configuration. - * @param log Logger. - * @param locJvmGrid Local jvm grid. - */ - public IgniteExProcessProxy(final IgniteConfiguration cfg, final IgniteLogger log, final Ignite locJvmGrid) throws Exception { - this.cfg = cfg; - this.locJvmGrid = locJvmGrid; - this.log = log.getLogger("jvm-" + id); - - IgniteNodeRunner.storeToFile(cfg.getCacheConfiguration()[0]); - - List<String> jvmArgs = U.jvmArgs(); - - List<String> filteredJvmArgs = new ArrayList<>(); - - for (String arg : jvmArgs) { - if(!arg.toLowerCase().startsWith("-agentlib")) - filteredJvmArgs.add(arg); - } - - proc = GridJavaProcess.exec( - IgniteNodeRunner.class, - IgniteNodeRunner.asParams(id, cfg), // Params. - this.log, - // Optional closure to be called each time wrapped process prints line to system.out or system.err. - new IgniteInClosure<String>() { - @Override public void apply(String s) { - IgniteExProcessProxy.this.log.info(s); - } - }, - null, - filteredJvmArgs, // JVM Args. - System.getProperty("surefire.test.class.path") - ); - - // TODO: delete sleep. - U.sleep(3_000); - - gridProxies.put(cfg.getGridName(), this); - - compute = locJvmGrid.compute(locJvmGrid.cluster().forNodeId(id)); - } - - /** - * @param gridName Grid name. - * @return Instance by name or <code>null</code>. - */ - public static IgniteExProcessProxy get(String gridName) { - return gridProxies.get(gridName); - } - - /** - * Kill all running processes. - * - * @throws Exception if failed. - */ - public static void killAll() throws Exception { - for (IgniteExProcessProxy ignite : gridProxies.values()) - try { - ignite.getProcess().kill(); - } - catch (Exception e) { - U.error(ignite.log, "Killing failed.", e); - } - - gridProxies.clear(); - } - - /** - * @return Local JVM grid instance. - */ - public Ignite localJvmGrid() { - return locJvmGrid; - } - - /** - * @return Grid id. - */ - public UUID getId() { - return id; - } - - /** {@inheritDoc} */ - @Override public String name() { - return cfg.getGridName(); - } - - /** {@inheritDoc} */ - @Override public IgniteLogger log() { - return log; - } - - /** {@inheritDoc} */ - @Override public IgniteConfiguration configuration() { - return cfg; - } - - /** {@inheritDoc} */ - @Override public <K extends GridCacheUtilityKey, V> IgniteInternalCache<K, V> utilityCache() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Nullable @Override public <K, V> IgniteInternalCache<K, V> cachex(@Nullable String name) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Nullable @Override public <K, V> IgniteInternalCache<K, V> cachex() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public Collection<IgniteInternalCache<?, ?>> cachesx( - @Nullable IgnitePredicate<? super IgniteInternalCache<?, ?>>... p) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public boolean eventUserRecordable(int type) { - return false; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public boolean allEventsUserRecordable(int[] types) { - return false; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public boolean isJmxRemoteEnabled() { - return false; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public boolean isRestartEnabled() { - return false; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Nullable @Override public IgniteFileSystem igfsx(@Nullable String name) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public Hadoop hadoop() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteClusterEx cluster() { - return (IgniteClusterEx)locJvmGrid.cluster(); - } - - /** {@inheritDoc} */ - @Nullable @Override public String latestVersion() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public ClusterNode localNode() { - return F.first(compute.broadcast(new IgniteClosureX<Object, ClusterNode>() { - @Override public ClusterNode applyx(Object o) { - return ((IgniteEx)Ignition.ignite(id)).localNode(); - } - }, null)); - } - - /** {@inheritDoc} */ - @Override public GridKernalContext context() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteCompute compute() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteCompute compute(ClusterGroup grp) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteMessaging message() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteMessaging message(ClusterGroup grp) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteEvents events() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteEvents events(ClusterGroup grp) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteServices services() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteServices services(ClusterGroup grp) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public ExecutorService executorService() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public ExecutorService executorService(ClusterGroup grp) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteProductVersion version() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteScheduler scheduler() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <K, V> IgniteCache<K, V> createCache(CacheConfiguration<K, V> cacheCfg) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <K, V> IgniteCache<K, V> createCache(String cacheName) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K, V> cacheCfg) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <K, V> IgniteCache<K, V> getOrCreateCache(String cacheName) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <K, V> void addCacheConfiguration(CacheConfiguration<K, V> cacheCfg) { - // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <K, V> IgniteCache<K, V> createCache(CacheConfiguration<K, V> cacheCfg, - NearCacheConfiguration<K, V> nearCfg) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K, V> cacheCfg, - NearCacheConfiguration<K, V> nearCfg) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <K, V> IgniteCache<K, V> createNearCache(@Nullable String cacheName, NearCacheConfiguration<K, V> nearCfg) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <K, V> IgniteCache<K, V> getOrCreateNearCache(@Nullable String cacheName, - NearCacheConfiguration<K, V> nearCfg) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public void destroyCache(String cacheName) { - // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <K, V> IgniteCache<K, V> cache(@Nullable final String name) { - return new IgniteCacheProcessProxy(name, this); - } - - /** {@inheritDoc} */ - @Override public IgniteTransactions transactions() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <K, V> IgniteDataStreamer<K, V> dataStreamer(@Nullable String cacheName) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteFileSystem fileSystem(String name) { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public Collection<IgniteFileSystem> fileSystems() { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteAtomicSequence atomicSequence(String name, long initVal, boolean create) throws IgniteException { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteAtomicLong atomicLong(String name, long initVal, boolean create) throws IgniteException { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <T> IgniteAtomicReference<T> atomicReference(String name, @Nullable T initVal, - boolean create) throws IgniteException { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <T, S> IgniteAtomicStamped<T, S> atomicStamped(String name, @Nullable T initVal, @Nullable S initStamp, - boolean create) throws IgniteException { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public IgniteCountDownLatch countDownLatch(String name, int cnt, boolean autoDel, - boolean create) throws IgniteException { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <T> IgniteQueue<T> queue(String name, int cap, - @Nullable CollectionConfiguration cfg) throws IgniteException { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <T> IgniteSet<T> set(String name, @Nullable CollectionConfiguration cfg) throws IgniteException { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public <T extends IgnitePlugin> T plugin(String name) throws PluginNotFoundException { - return null; // TODO: CODE: implement. - } - - /** {@inheritDoc} */ - @Override public void close() throws IgniteException { - try { - getProcess().kill(); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - /** {@inheritDoc} */ - @Override public <K> Affinity<K> affinity(String cacheName) { - return null; // TODO: CODE: implement. - } - - public GridJavaProcess getProcess() { - return proc; - } - - public static Ignite grid(@Nullable String name) { -// IgniteNamedInstance grid = name != null ? grids.get(name) : dfltGrid; - - Ignite res = gridProxies.get(name); - - if (res == null) - throw new IgniteIllegalStateException("Grid instance was not properly started " + - "or was already stopped: " + name); - - return res; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36b9829a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteNodeRunner.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteNodeRunner.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteNodeRunner.java deleted file mode 100644 index 32f33dc..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteNodeRunner.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.cache.multijvm; - -import org.apache.ignite.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.marshaller.optimized.*; -import org.apache.ignite.spi.discovery.tcp.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.*; -import org.apache.ignite.testframework.junits.*; - -import java.io.*; -import java.util.*; - -/** - * Run ignite node. - */ -public class IgniteNodeRunner { - /** VM ip finder for TCP discovery. */ - public static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder(); - - /** */ - private static final String CACHE_CONFIGURATION_TMP_FILE = System.getProperty("java.io.tmpdir") + - File.separator + "cacheConfiguration.tmp"; - - /** - * Starts {@link Ignite} instance accorging to given arguments. - * - * @param args Arguments. - * @throws Exception If failed. - */ - public static void main(String[] args) throws Exception { - try { - X.println(GridJavaProcess.PID_MSG_PREFIX + U.jvmPid()); - - X.println("Starting Ignite Node... Args" + Arrays.toString(args)); - - IgniteConfiguration cfg = configuration(args); - - Ignition.start(cfg); - } - catch (Throwable e) { - e.printStackTrace(); - - System.exit(1); - } - } - - /** - * @param id Grid id. - * @param cfg Configuration. - * @return Given paramethers as command line string arguments. - */ - public static String asParams(UUID id, IgniteConfiguration cfg) { - return id.toString() + ' ' + cfg.getGridName(); - } - - /** - * @param args Command line args. - * @return Ignite configuration. - * @throws Exception If failed. - */ - private static IgniteConfiguration configuration(String[] args) throws Exception { - // Parse args. - assert args != null && args.length >= 1; - - final UUID nodeId = UUID.fromString(args[0]); - final String gridName = args[1]; - - // Configuration. - IgniteConfiguration cfg = GridAbstractTest.getConfiguration0(gridName, new IgniteTestResources(), - GridCachePartitionedMultiJvmFullApiSelfTest.class, false); - - TcpDiscoverySpi disco = new TcpDiscoverySpi(); - -// disco.setMaxMissedHeartbeats(Integer.MAX_VALUE); - - disco.setIpFinder(ipFinder); - -// if (isDebug()) -// disco.setAckTimeout(Integer.MAX_VALUE); - - cfg.setDiscoverySpi(disco); - - cfg.setCacheConfiguration(cacheConfiguration()); - - cfg.setMarshaller(new OptimizedMarshaller(false)); -//// ---------------- -//// if (offHeapValues()) -//// cfg.setSwapSpaceSpi(new GridTestSwapSpaceSpi()); -//// ---------------- -// cfg.getTransactionConfiguration().setTxSerializableEnabled(true); -// -//// --------------- -// Special. - cfg.setLocalHost("127.0.0.1"); - - cfg.setIncludeProperties(); - - cfg.setNodeId(nodeId); - - return cfg; - } - - /** - * Stors given cache configuration to the file. - * - * @param cc Cache configuration. - * @throws IOException If exception. - */ - public static void storeToFile(CacheConfiguration cc) throws IOException { - File ccfgTmpFile = new File(CACHE_CONFIGURATION_TMP_FILE); - - // TODO: add file created check (and delete the file after tests). - boolean created = ccfgTmpFile.createNewFile(); - - try(ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(ccfgTmpFile))) { - out.writeObject(cc); - } - } - - /** - * Reads cache configuration from the file. - * - * @return Cache configuration. - * @throws Exception If exception. - */ - private static CacheConfiguration cacheConfiguration() throws Exception { - File ccfgTmpFile = new File(CACHE_CONFIGURATION_TMP_FILE); - - try(ObjectInputStream in = new ObjectInputStream(new FileInputStream(ccfgTmpFile))) { - return (CacheConfiguration)in.readObject(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36b9829a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/FileMarshallerContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/FileMarshallerContext.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/FileMarshallerContext.java new file mode 100644 index 0000000..2aebe52 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/FileMarshallerContext.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache.multijvm.framework; + +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.marshaller.*; + +import java.io.*; +import java.util.*; + +/** + * TODO: Add class description. + */ +public class FileMarshallerContext extends MarshallerContextTestImpl { + /** + * Default constructor. + */ + public FileMarshallerContext() { + } + + /** + * @param map Map. + */ + public FileMarshallerContext(Map<Integer, String> map) { + super(map); + } + + public void storeToFile(String fileName) throws IOException { + File file = new File(fileName); + + // TODO: add file created check (and delete the file after tests). + boolean created = file.createNewFile(); + + try(ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file))) { + out.writeObject(new HashMap<>(map)); + } + } + + public static FileMarshallerContext fromFile(String fileName) throws IOException, ClassNotFoundException { + try(ObjectInputStream in = new ObjectInputStream(new FileInputStream(new File(fileName)))) { + Map<Integer, String> map = (Map<Integer, String>)in.readObject(); + + X.println("Map=" + map); + + return new FileMarshallerContext(map); + } + } + + public Map getMap() { + return map; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36b9829a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/IgniteCacheProcessProxy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/IgniteCacheProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/IgniteCacheProcessProxy.java new file mode 100644 index 0000000..6f4bf18 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/IgniteCacheProcessProxy.java @@ -0,0 +1,500 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache.multijvm.framework; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.cluster.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.mxbean.*; +import org.jetbrains.annotations.*; + +import javax.cache.*; +import javax.cache.CacheManager; +import javax.cache.configuration.*; +import javax.cache.expiry.*; +import javax.cache.integration.*; +import javax.cache.processor.*; +import java.util.*; +import java.util.concurrent.locks.*; + +/** + * Ignite cache proxy for ignite instance at another JVM. + */ +public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> { + /** Compute. */ + private final transient IgniteCompute compute; + + /** Cache name. */ + private final String cacheName; + + /** Grid id. */ + private final UUID gridId; + + /** + * @param name Name. + * @param proxy Ignite Process Proxy. + */ + public IgniteCacheProcessProxy(String name, IgniteExProcessProxy proxy) { + cacheName = name; + gridId = proxy.getId(); + + ClusterGroup grp = proxy.localJvmGrid().cluster().forNodeId(proxy.getId()); + + compute = proxy.localJvmGrid().compute(grp); + } + + /** {@inheritDoc} */ + @Override public IgniteCache<K, V> withAsync() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public boolean isAsync() { + return false; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <R> IgniteFuture<R> future() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <C extends Configuration<K, V>> C getConfiguration(Class<C> clazz) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public Entry<K, V> randomEntry() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteCache<K, V> withExpiryPolicy(ExpiryPolicy plc) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteCache<K, V> withSkipStore() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public void loadCache(@Nullable IgniteBiPredicate<K, V> p, @Nullable Object... args) throws CacheException { + // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public void localLoadCache(@Nullable IgniteBiPredicate<K, V> p, @Nullable Object... args) throws CacheException { + // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public V getAndPutIfAbsent(final K key, final V val) throws CacheException { + return (V)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).getAndPutIfAbsent(key, val); + } + }); + } + + /** {@inheritDoc} */ + @Override public Lock lock(K key) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public Lock lockAll(Collection<? extends K> keys) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public boolean isLocalLocked(K key, boolean byCurrThread) { + return false; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <R> QueryCursor<R> query(Query<R> qry) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override public Iterable<Entry<K, V>> localEntries(CachePeekMode... peekModes) throws CacheException { + // TODO: implement. +// return F.first(compute.broadcast(new IgniteClosureX<CachePeekMode[], Iterable>() { +// @Override public Iterable applyx(CachePeekMode... modes) { +// return Ignition.ignite(gridId).cache(cacheName).localEntries(modes); +// } +// }, peekModes)); + + return Collections.emptyList(); + } + + /** {@inheritDoc} */ + @Override public QueryMetrics queryMetrics() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public void localEvict(Collection<? extends K> keys) { + // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public V localPeek(final K key, final CachePeekMode... peekModes) { + return (V)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).localPeek(key, peekModes); + } + }); + } + + /** {@inheritDoc} */ + @Override public void localPromote(Set<? extends K> keys) throws CacheException { + // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public int size(final CachePeekMode... peekModes) throws CacheException { + return (int)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).size(peekModes); + } + }); + } + + /** {@inheritDoc} */ + @Override public int localSize(final CachePeekMode... peekModes) { + return (int)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).localSize(peekModes); + } + }); + } + + /** {@inheritDoc} */ + @Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(Map<? extends K, ? extends EntryProcessor<K, V, T>> map, + Object... args) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public V get(final K key) { + return (V)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).get(key); + } + }); + } + + /** {@inheritDoc} */ + @Override public Map<K, V> getAll(final Set<? extends K> keys) { + return (Map<K, V>)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).getAll(keys); + } + }); + } + + /** {@inheritDoc} */ + @Override public boolean containsKey(final K key) { + return (boolean)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).containsKey(key); + } + }); + } + + /** {@inheritDoc} */ + @Override public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener) { + // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public boolean containsKeys(final Set<? extends K> keys) { + return (boolean)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).containsKeys(keys); + } + }); + } + + /** {@inheritDoc} */ + @Override public void put(final K key, final V val) {; + compute.run(new IgniteRunnable() { + @Override public void run() { + Ignition.ignite(gridId).cache(cacheName).put(key, val); + } + }); + } + + /** {@inheritDoc} */ + @Override public V getAndPut(final K key, final V val) { + return (V)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).getAndPut(key, val); + } + }); + } + + /** {@inheritDoc} */ + @Override public void putAll(final Map<? extends K, ? extends V> map) { + compute.run(new IgniteRunnable() { + @Override public void run() { + Ignition.ignite(gridId).cache(cacheName).putAll(map); + } + }); + } + + /** {@inheritDoc} */ + @Override public boolean putIfAbsent(final K key, final V val) { + return (boolean)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).putIfAbsent(key, val); + } + }); + } + + /** {@inheritDoc} */ + @Override public boolean remove(final K key) { + return (boolean)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).remove(key); + } + }); + } + + /** {@inheritDoc} */ + @Override public boolean remove(final K key, final V oldVal) { + return (boolean)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).remove(key, oldVal); + } + }); + } + + /** {@inheritDoc} */ + @Override public V getAndRemove(final K key) { + return (V)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).getAndRemove(key); + } + }); + } + + /** {@inheritDoc} */ + @Override public boolean replace(final K key, final V oldVal, final V newVal) { + return (boolean)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).replace(key, oldVal, newVal); + } + }); + } + + /** {@inheritDoc} */ + @Override public boolean replace(final K key, final V val) { + return (boolean)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).replace(key, val); + } + }); + } + + /** {@inheritDoc} */ + @Override public V getAndReplace(final K key, final V val) { + return (V)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).getAndReplace(key, val); + } + }); + } + + /** {@inheritDoc} */ + @Override public void removeAll(final Set<? extends K> keys) { + compute.run(new IgniteRunnable() { + @Override public void run() { + Ignition.ignite(gridId).cache(cacheName).removeAll(keys); + } + }); + } + + /** {@inheritDoc} */ + @Override public void removeAll() { + compute.run(new IgniteRunnable() { + @Override public void run() { + Ignition.ignite(gridId).cache(cacheName).removeAll(); + } + }); + } + + /** {@inheritDoc} */ + @Override public void clear() { + compute.run(new IgniteRunnable() { + @Override public void run() { + Ignition.ignite(gridId).cache(cacheName).clear(); + } + }); + } + + /** {@inheritDoc} */ + @Override public void clear(final K key) { + compute.run(new IgniteRunnable() { + @Override public void run() { + Ignition.ignite(gridId).cache(cacheName).clear(key); + } + }); + } + + /** {@inheritDoc} */ + @Override public void clearAll(final Set<? extends K> keys) { + compute.run(new IgniteRunnable() { + @Override public void run() { + Ignition.ignite(gridId).cache(cacheName).clearAll(keys); + } + }); + } + + /** {@inheritDoc} */ + @Override public void localClear(final K key) { + compute.run(new IgniteRunnable() { + @Override public void run() { + Ignition.ignite(gridId).cache(cacheName).localClear(key); + } + }); + } + + /** {@inheritDoc} */ + @Override public void localClearAll(final Set<? extends K> keys) { + compute.run(new IgniteRunnable() { + @Override public void run() { + Ignition.ignite(gridId).cache(cacheName).localClearAll(keys); + } + }); + } + + /** {@inheritDoc} */ + @Override public <T> T invoke(final K key, final EntryProcessor<K, V, T> entryProcessor, final Object... arguments) { + return (T)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).invoke(key, + (EntryProcessor<Object, Object, Object>)entryProcessor, arguments); + } + }); + } + + /** {@inheritDoc} */ + @Override public <T> T invoke(final K key, final CacheEntryProcessor<K, V, T> entryProcessor, final Object... arguments) { + return (T)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).invoke(key, + (CacheEntryProcessor<Object, Object, Object>)entryProcessor, arguments); + } + }); + } + + /** {@inheritDoc} */ + @Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(final Set<? extends K> keys, final EntryProcessor<K, V, T> entryProcessor, + final Object... args) { + return (Map<K, EntryProcessorResult<T>>)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).invokeAll(keys, + (EntryProcessor<Object, Object, Object>)entryProcessor, args); + } + }); + } + + /** {@inheritDoc} */ + @Override public String getName() { + return (String)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).getName(); + } + }); + } + + /** {@inheritDoc} */ + @Override public CacheManager getCacheManager() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public void close() { + compute.run(new IgniteRunnable() { + @Override public void run() { + Ignition.ignite(gridId).cache(cacheName).close(); + } + }); + } + + /** {@inheritDoc} */ + @Override public boolean isClosed() { + return (boolean)compute.call(new IgniteCallable<Object>() { + @Override public Object call() throws Exception { + return Ignition.ignite(gridId).cache(cacheName).isClosed(); + } + }); + } + + /** {@inheritDoc} */ + @Override public <T> T unwrap(Class<T> clazz) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public void registerCacheEntryListener(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) { + // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public void deregisterCacheEntryListener(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) { + // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public Iterator<Entry<K, V>> iterator() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, + CacheEntryProcessor<K, V, T> entryProcessor, Object... args) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteFuture<?> rebalance() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public CacheMetrics metrics() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public CacheMetrics metrics(ClusterGroup grp) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public CacheMetricsMXBean mxBean() { + return null; // TODO: CODE: implement. + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36b9829a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/IgniteExProcessProxy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/IgniteExProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/IgniteExProcessProxy.java new file mode 100644 index 0000000..9cd3ab1 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/IgniteExProcessProxy.java @@ -0,0 +1,449 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache.multijvm.framework; + +import org.apache.ignite.*; +import org.apache.ignite.cache.affinity.*; +import org.apache.ignite.cluster.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.internal.cluster.*; +import org.apache.ignite.internal.processors.cache.*; +import org.apache.ignite.internal.processors.hadoop.*; +import org.apache.ignite.internal.util.*; +import org.apache.ignite.internal.util.lang.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.plugin.*; +import org.jetbrains.annotations.*; + +import java.util.*; +import java.util.concurrent.*; + +/** + * Ignite proxy for ignite instance at another JVM. + */ +public class IgniteExProcessProxy implements IgniteEx { + /** Grid proxies. */ + private transient static final Map<String, IgniteExProcessProxy> gridProxies = new HashMap<>(); + + /** Jvm process with ignite instance. */ + private transient final GridJavaProcess proc; + + /** Configuration. */ + private transient final IgniteConfiguration cfg; + + /** Local jvm grid. */ + private transient final Ignite locJvmGrid; + + /** Logger. */ + private transient final IgniteLogger log; + + /** Grid id. */ + private final UUID id = UUID.randomUUID(); + + /** Compute. */ + private transient final IgniteCompute compute; + + /** + * @param cfg Configuration. + * @param log Logger. + * @param locJvmGrid Local jvm grid. + */ + public IgniteExProcessProxy(final IgniteConfiguration cfg, final IgniteLogger log, final Ignite locJvmGrid) throws Exception { + this.cfg = cfg; + this.locJvmGrid = locJvmGrid; + this.log = log.getLogger("jvm-" + id); + + IgniteNodeRunner.storeToFile(IgniteNodeRunner.IGNITE_CONFIGURATION_TMP_FILE, cfg); + + List<String> jvmArgs = U.jvmArgs(); + + List<String> filteredJvmArgs = new ArrayList<>(); + + for (String arg : jvmArgs) { + if(!arg.toLowerCase().startsWith("-agentlib")) + filteredJvmArgs.add(arg); + } + + proc = GridJavaProcess.exec( + IgniteNodeRunner.class, + IgniteNodeRunner.asParams(id, cfg), // Params. + this.log, + // Optional closure to be called each time wrapped process prints line to system.out or system.err. + new IgniteInClosure<String>() { + @Override public void apply(String s) { + IgniteExProcessProxy.this.log.info(s); + } + }, + null, + filteredJvmArgs, // JVM Args. + System.getProperty("surefire.test.class.path") + ); + + // TODO: delete sleep. + U.sleep(3_000); + + gridProxies.put(cfg.getGridName(), this); + + compute = locJvmGrid.compute(locJvmGrid.cluster().forNodeId(id)); + } + + /** + * @param gridName Grid name. + * @return Instance by name or <code>null</code>. + */ + public static IgniteExProcessProxy get(String gridName) { + return gridProxies.get(gridName); + } + + /** + * Kill all running processes. + * + * @throws Exception if failed. + */ + public static void killAll() throws Exception { + for (IgniteExProcessProxy ignite : gridProxies.values()) + try { + ignite.getProcess().kill(); + } + catch (Exception e) { + U.error(ignite.log, "Killing failed.", e); + } + + gridProxies.clear(); + } + + /** + * @return Local JVM grid instance. + */ + public Ignite localJvmGrid() { + return locJvmGrid; + } + + /** + * @return Grid id. + */ + public UUID getId() { + return id; + } + + /** {@inheritDoc} */ + @Override public String name() { + return cfg.getGridName(); + } + + /** {@inheritDoc} */ + @Override public IgniteLogger log() { + return log; + } + + /** {@inheritDoc} */ + @Override public IgniteConfiguration configuration() { + return cfg; + } + + /** {@inheritDoc} */ + @Override public <K extends GridCacheUtilityKey, V> IgniteInternalCache<K, V> utilityCache() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Nullable @Override public <K, V> IgniteInternalCache<K, V> cachex(@Nullable String name) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Nullable @Override public <K, V> IgniteInternalCache<K, V> cachex() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public Collection<IgniteInternalCache<?, ?>> cachesx( + @Nullable IgnitePredicate<? super IgniteInternalCache<?, ?>>... p) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public boolean eventUserRecordable(int type) { + return false; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public boolean allEventsUserRecordable(int[] types) { + return false; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public boolean isJmxRemoteEnabled() { + return false; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public boolean isRestartEnabled() { + return false; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Nullable @Override public IgniteFileSystem igfsx(@Nullable String name) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public Hadoop hadoop() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteClusterEx cluster() { + return (IgniteClusterEx)locJvmGrid.cluster(); + } + + /** {@inheritDoc} */ + @Nullable @Override public String latestVersion() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public ClusterNode localNode() { + return F.first(compute.broadcast(new IgniteClosureX<Object, ClusterNode>() { + @Override public ClusterNode applyx(Object o) { + return ((IgniteEx)Ignition.ignite(id)).localNode(); + } + }, null)); + } + + /** {@inheritDoc} */ + @Override public GridKernalContext context() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteCompute compute() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteCompute compute(ClusterGroup grp) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteMessaging message() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteMessaging message(ClusterGroup grp) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteEvents events() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteEvents events(ClusterGroup grp) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteServices services() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteServices services(ClusterGroup grp) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public ExecutorService executorService() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public ExecutorService executorService(ClusterGroup grp) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteProductVersion version() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteScheduler scheduler() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> createCache(CacheConfiguration<K, V> cacheCfg) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> createCache(String cacheName) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K, V> cacheCfg) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> getOrCreateCache(String cacheName) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <K, V> void addCacheConfiguration(CacheConfiguration<K, V> cacheCfg) { + // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> createCache(CacheConfiguration<K, V> cacheCfg, + NearCacheConfiguration<K, V> nearCfg) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K, V> cacheCfg, + NearCacheConfiguration<K, V> nearCfg) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> createNearCache(@Nullable String cacheName, NearCacheConfiguration<K, V> nearCfg) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> getOrCreateNearCache(@Nullable String cacheName, + NearCacheConfiguration<K, V> nearCfg) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public void destroyCache(String cacheName) { + // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> cache(@Nullable final String name) { + return new IgniteCacheProcessProxy(name, this); + } + + /** {@inheritDoc} */ + @Override public IgniteTransactions transactions() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteDataStreamer<K, V> dataStreamer(@Nullable String cacheName) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteFileSystem fileSystem(String name) { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public Collection<IgniteFileSystem> fileSystems() { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteAtomicSequence atomicSequence(String name, long initVal, boolean create) throws IgniteException { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteAtomicLong atomicLong(String name, long initVal, boolean create) throws IgniteException { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <T> IgniteAtomicReference<T> atomicReference(String name, @Nullable T initVal, + boolean create) throws IgniteException { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <T, S> IgniteAtomicStamped<T, S> atomicStamped(String name, @Nullable T initVal, @Nullable S initStamp, + boolean create) throws IgniteException { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public IgniteCountDownLatch countDownLatch(String name, int cnt, boolean autoDel, + boolean create) throws IgniteException { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <T> IgniteQueue<T> queue(String name, int cap, + @Nullable CollectionConfiguration cfg) throws IgniteException { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <T> IgniteSet<T> set(String name, @Nullable CollectionConfiguration cfg) throws IgniteException { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public <T extends IgnitePlugin> T plugin(String name) throws PluginNotFoundException { + return null; // TODO: CODE: implement. + } + + /** {@inheritDoc} */ + @Override public void close() throws IgniteException { + try { + getProcess().kill(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + /** {@inheritDoc} */ + @Override public <K> Affinity<K> affinity(String cacheName) { + return null; // TODO: CODE: implement. + } + + public GridJavaProcess getProcess() { + return proc; + } + + public static Ignite grid(@Nullable String name) { +// IgniteNamedInstance grid = name != null ? grids.get(name) : dfltGrid; + + Ignite res = gridProxies.get(name); + + if (res == null) + throw new IgniteIllegalStateException("Grid instance was not properly started " + + "or was already stopped: " + name); + + return res; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36b9829a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/IgniteNodeRunner.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/IgniteNodeRunner.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/IgniteNodeRunner.java new file mode 100644 index 0000000..fd09f1e --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/framework/IgniteNodeRunner.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache.multijvm.framework; + +import org.apache.ignite.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.util.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.marshaller.optimized.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.*; +import org.jetbrains.annotations.*; + +import java.io.*; +import java.util.*; + +/** + * Run ignite node. + */ +public class IgniteNodeRunner { + /** VM ip finder for TCP discovery. */ + public static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder(); + + /** */ + public static final String IGNITE_CONFIGURATION_TMP_FILE = System.getProperty("java.io.tmpdir") + + File.separator + "igniteConfiguration.tmp"; + + /** + * Starts {@link Ignite} instance accorging to given arguments. + * + * @param args Arguments. + * @throws Exception If failed. + */ + public static void main(String[] args) throws Exception { + try { + X.println(GridJavaProcess.PID_MSG_PREFIX + U.jvmPid()); + + X.println("Starting Ignite Node... Args" + Arrays.toString(args)); + + IgniteConfiguration cfg = configuration(IGNITE_CONFIGURATION_TMP_FILE); + + Ignition.start(cfg); + } + catch (Throwable e) { + e.printStackTrace(); + + System.exit(1); + } + } + + /** + * @param id Grid id. + * @param cfg Configuration. + * @return Given paramethers as command line string arguments. + */ + public static String asParams(UUID id, IgniteConfiguration cfg) { + return id.toString() + ' ' + cfg.getGridName(); + } + + /** + * @param fileName File name of file with serialized configuration. + * @return Ignite configuration. + * @throws Exception If failed. + */ + private static IgniteConfiguration configuration(String fileName) throws Exception { + try(ObjectInputStream in = new ObjectInputStream(new FileInputStream(new File(fileName)))) { + OptimizedMarshaller marshaller = new OptimizedMarshaller(false); + + FileMarshallerContext ctx = FileMarshallerContext.fromFile(fileName + "_ctx"); + + X.println("Map 2=" + ctx.getMap().toString()); + + marshaller.setContext(ctx); + + IgniteConfiguration cfg = (IgniteConfiguration)marshaller.unmarshal(in, U.gridClassLoader()); + + X.println(">>>>> Cfg=" + cfg); + + return cfg; + } + } + + /** + * Stors configuration to file. + * + * @param fileName File name to store. + * @param cfg Configuration. + */ + public static void storeToFile(final String fileName, IgniteConfiguration cfg) throws Exception { + File ccfgTmpFile = new File(fileName); + + // TODO: add file created check (and delete the file after tests). + boolean created = ccfgTmpFile.createNewFile(); + + try(ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(ccfgTmpFile))) { + OptimizedMarshaller marshaller = new OptimizedMarshaller(false) { + @Override public void marshal(@Nullable Object obj, OutputStream out) throws IgniteCheckedException { + try { + super.marshal(obj, out); + + ((FileMarshallerContext)ctx).storeToFile(fileName + "_ctx"); + } + catch (IOException e) { + throw new IgniteCheckedException(e); + } + } + }; + + marshaller.setContext(new FileMarshallerContext()); + + marshaller.marshal(cfg, out); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36b9829a/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java b/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java index 095a404..1852ee4 100644 --- a/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java +++ b/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java @@ -20,6 +20,7 @@ package org.apache.ignite.marshaller; import org.apache.ignite.internal.*; import org.jsr166.*; +import java.util.*; import java.util.concurrent.*; /** @@ -27,7 +28,20 @@ import java.util.concurrent.*; */ public class MarshallerContextTestImpl extends MarshallerContextAdapter { /** */ - private final ConcurrentMap<Integer, String> map = new ConcurrentHashMap8<>(); + protected final ConcurrentMap<Integer, String> map = new ConcurrentHashMap8<>(); + + /** + * Default constructor. + */ + public MarshallerContextTestImpl() { + } + + /** + * @param map Map. + */ + public MarshallerContextTestImpl(Map<Integer, String> map) { + this.map.putAll(map); + } /** {@inheritDoc} */ @Override protected boolean registerClassName(int id, String clsName) {