Skip to content

Commit

Permalink
IGNITE-11634: SQL: Fixed anonymous class handling in DmlStatementsPro…
Browse files Browse the repository at this point in the history
…cessor. This closes apache#6349.
  • Loading branch information
gromtech authored and devozerov committed Mar 28, 2019
1 parent 4c3c2e5 commit 9dab4e4
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,21 @@ public ModifyingEntryProcessor(Object val, IgniteInClosure<MutableEntry<Object,
}
};

/** Dummy anonymous class to advance RMV anonymous value to 5. */
private static final Runnable DUMMY_4 = new Runnable() {
@Override public void run() {
// No-op.
}
};
/** Remove updater for compatibility with < 2.7.0. Must not be moved around to keep at anonymous position 4. */
public static final IgniteInClosure<MutableEntry<Object, Object>> RMV_OLD =
new IgniteInClosure<MutableEntry<Object, Object>>() {
@Override public void apply(MutableEntry<Object, Object> e) {
e.remove();
}
};

/** Remove updater. Must not be moved around to keep at anonymous position 5. */
public static final IgniteInClosure<MutableEntry<Object, Object>> RMV =
new IgniteInClosure<MutableEntry<Object, Object>>() {
@Override public void apply(MutableEntry<Object, Object> e) {
e.remove();
}
};
@Override public void apply(MutableEntry<Object, Object> e) {
e.remove();
}
};

/**
* Entry value updater.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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.query.h2;

import javax.cache.processor.MutableEntry;
import org.apache.ignite.lang.IgniteInClosure;
import org.junit.Assert;
import org.junit.Test;

/**
* Ensures that abstart classes of entry modifiers are compatible with old versions.
*/
public class DmlStatementsProcessorTest {
/**
* Checks that remove-closure is available by anonymous class position (4).
* This is required for compatibility with versions < 2.7.0.
*
* @throws Exception If failed.
*/
@Test
public void testRemoveEntryModifierCompatibilityOld() throws Exception {
checkRemoveClosureByAnonymousPosition(4);
}

/**
* Checks that remove-closure is available by anonymous class position (5).
* This is required for compatibility with versions >= 2.7.0.
*
* @throws Exception If failed.
*/
@Test
public void testRemoveEntryModifierCompatibilityNew() throws Exception {
checkRemoveClosureByAnonymousPosition(5);
}

/**
* Checks that remove-closure is available by anonymous class position.
*/
private void checkRemoveClosureByAnonymousPosition(int position) throws Exception {
Class<?> cls = Class.forName(DmlStatementsProcessor.class.getName() + "$" + position);

IgniteInClosure<MutableEntry<Object, Object>> rmvC =
(IgniteInClosure<MutableEntry<Object, Object>>)cls.newInstance();

CustomMutableEntry<Object, Object> entry = new CustomMutableEntry<>();

rmvC.apply(entry);

Assert.assertTrue("Entry should be removed", entry.isRemoved());
}

/**
*
*/
private static class CustomMutableEntry<K, V> implements MutableEntry<K, V> {
/** */
private boolean rmvd;

/**
* @return {@code true} if remove method was called.
*/
private boolean isRemoved() {
return rmvd;
}

/** {@inheritDoc} */
@Override public boolean exists() {
return false;
}

/** {@inheritDoc} */
@Override public void remove() {
rmvd = true;
}

/** {@inheritDoc} */
@Override public void setValue(V v) {
// No-op.
}

/** {@inheritDoc} */
@Override public K getKey() {
return null;
}

/** {@inheritDoc} */
@Override public V getValue() {
return null;
}

/** {@inheritDoc} */
@Override public <T> T unwrap(Class<T> aCls) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.ignite.internal.processors.query.LocalQueryLazyTest;
import org.apache.ignite.internal.processors.query.SqlLocalQueryConnectionAndStatementTest;
import org.apache.ignite.internal.processors.query.h2.CacheQueryEntityWithDateTimeApiFieldsTest;
import org.apache.ignite.internal.processors.query.h2.DmlStatementsProcessorTest;
import org.apache.ignite.internal.processors.query.h2.twostep.CacheQueryMemoryLeakTest;
import org.apache.ignite.internal.processors.query.h2.twostep.CreateTableWithDateKeySelfTest;
import org.apache.ignite.internal.processors.query.h2.twostep.DisappearedCacheCauseRetryMessageSelfTest;
Expand Down Expand Up @@ -120,6 +121,8 @@

CacheQueryEntityWithDateTimeApiFieldsTest.class,

DmlStatementsProcessorTest.class,

NonCollocatedRetryMessageSelfTest.class,
RetryCauseMessageSelfTest.class,
DisappearedCacheCauseRetryMessageSelfTest.class,
Expand Down

0 comments on commit 9dab4e4

Please sign in to comment.