Skip to content

Commit

Permalink
IGNITE-14071 .NET: RegisterSameJavaType mode enabled for messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov committed Feb 22, 2022
1 parent 8ec78ed commit 4f7579d
Show file tree
Hide file tree
Showing 11 changed files with 385 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteException;
Expand All @@ -39,6 +40,7 @@
import org.apache.ignite.compute.ComputeJobAdapter;
import org.apache.ignite.compute.ComputeJobResult;
import org.apache.ignite.compute.ComputeTaskAdapter;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.binary.BinaryArray;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.U;
Expand All @@ -52,10 +54,15 @@
import org.apache.ignite.platform.model.Parameter;
import org.apache.ignite.platform.model.Role;
import org.apache.ignite.platform.model.User;
import org.apache.ignite.platform.model.V5;
import org.apache.ignite.platform.model.V6;
import org.apache.ignite.platform.model.V7;
import org.apache.ignite.platform.model.V8;
import org.apache.ignite.platform.model.Value;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.apache.ignite.services.Service;
import org.apache.ignite.services.ServiceContext;
import org.apache.ignite.testframework.GridTestUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -490,26 +497,26 @@ public int testOverload(Integer count, Employee[] emps) {

/** */
public int testOverload(int count, Parameter[] params) {
assertNotNull(params);
assertEquals(count, params.length);
assert params != null;
assert count == params.length;

assertEquals(1, params[0].getId());
assertEquals(2, params[0].getValues().length);
assert 1 == params[0].getId();
assert 2 == params[0].getValues().length;

assertEquals(1, params[0].getValues()[0].getId());
assertEquals(42, params[0].getValues()[0].getVal());
assert 1 == params[0].getValues()[0].getId();
assert 42 == params[0].getValues()[0].getVal();

assertEquals(2, params[0].getValues()[1].getId());
assertEquals(43, params[0].getValues()[1].getVal());
assert 2 == params[0].getValues()[1].getId();
assert 43 == params[0].getValues()[1].getVal();

assertEquals(2, params[1].getId());
assertEquals(2, params[1].getValues().length);
assert 2 == params[1].getId();
assert 2 == params[1].getValues().length;

assertEquals(3, params[1].getValues()[0].getId());
assertEquals(44, params[1].getValues()[0].getVal());
assert 3 == params[1].getValues()[0].getId();
assert 44 == params[1].getValues()[0].getVal();

assertEquals(4, params[1].getValues()[1].getId());
assertEquals(45, params[1].getValues()[1].getVal());
assert 4 == params[1].getValues()[1].getId();
assert 45 == params[1].getValues()[1].getVal();

return 43;
}
Expand Down Expand Up @@ -644,6 +651,71 @@ public void testLocalDateFromCache() {
cache.put(8, ts2);
}

/** */
private final AtomicInteger cntMsgs = new AtomicInteger(0);

/** */
public void startReceiveMessage() {
ignite.message().localListen("test-topic-2", (node, obj) -> {
assert obj instanceof BinaryObject;

V6 v6 = ((BinaryObject)obj).deserialize();

assert "Sarah Connor".equals(v6.getName()) ||
"John Connor".equals(v6.getName()) ||
"Kyle Reese".equals(v6.getName());

cntMsgs.incrementAndGet();

return true;
});

ignite.message().localListen("test-topic-3", (node, obj) -> {
assert obj instanceof BinaryObject;

V7 v7 = ((BinaryObject)obj).deserialize();

assert "V7-1".equals(v7.getName()) ||
"V7-2".equals(v7.getName()) ||
"V7-3".equals(v7.getName());

cntMsgs.incrementAndGet();

return true;
});

ignite.message().localListen("test-topic-4", (node, obj) -> {
assert obj instanceof BinaryObject;

V8 v8 = ((BinaryObject)obj).deserialize();

assert "V8".equals(v8.getName()) ||
"V9".equals(v8.getName()) ||
"V10".equals(v8.getName());

cntMsgs.incrementAndGet();

return true;
});
}

/** */
public boolean testMessagesReceived() {
try {
return GridTestUtils.waitForCondition(() -> cntMsgs.get() == 9, 1_000 * 5);
}
catch (IgniteInterruptedCheckedException e) {
return false;
}
}

/** */
public void testSendMessage() {
ignite.message().sendOrdered("test-topic", new V5("1"), 1_000 * 5);
ignite.message().sendOrdered("test-topic", new V5("2"), 1_000 * 5);
ignite.message().sendOrdered("test-topic", new V5("3"), 1_000 * 5);
}

/** */
public void testException(String exCls) throws Exception {
switch (exCls) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.platform.model;

/** Test V5 object. */
public class V5 {
/** */
private final String name;

/** */
public V5(String name) {
this.name = name;
}

/** */
public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.platform.model;

/** Test V6 object. */
public class V6 {
/** */
private final String name;

/** */
public V6(String name) {
this.name = name;
}

/** */
public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.platform.model;

/** Test V7 object. */
public class V7 {
/** */
private final String name;

/** */
public V7(String name) {
this.name = name;
}

/** */
public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.platform.model;

/** Test V8 object. */
public class V8 {
/** */
private final String name;

/** */
public V8(String name) {
this.name = name;
}

/** */
public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ public interface IJavaService
/** */
void sleep(long delayMs);

/** */
void startReceiveMessage();

/** */
bool testMessagesReceived();

/** */
void testSendMessage();

/** */
object contextAttribute(string name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,24 @@ public void sleep(long delayMs)
_svc.sleep(delayMs);
}

/** <inheritDoc /> */
public void startReceiveMessage()
{
_svc.startReceiveMessage();
}

/** <inheritDoc /> */
public bool testMessagesReceived()
{
return _svc.testMessagesReceived();
}

/** <inheritDoc /> */
public void testSendMessage()
{
_svc.testSendMessage();
}

/** <inheritDoc /> */
public object testRoundtrip(object x)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,24 @@ public class V3 { public String Name { get; set; } }
/// A class is a clone of Java class V4 with the same namespace.
/// </summary>
public class V4 { public String Name { get; set; } }

/// <summary>
/// A class is a clone of Java class V5 with the same namespace.
/// </summary>
public class V5 { public String Name { get; set; } }

/// <summary>
/// A class is a clone of Java class V6 with the same namespace.
/// </summary>
public class V6 { public String Name { get; set; } }

/// <summary>
/// A class is a clone of Java class V6 with the same namespace.
/// </summary>
public class V7 { public String Name { get; set; } }

/// <summary>
/// A class is a clone of Java class V6 with the same namespace.
/// </summary>
public class V8 { public String Name { get; set; } }
}
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,24 @@ public void sleep(long delayMs)
throw new NotImplementedException();
}

/** <inheritDoc /> */
public void startReceiveMessage()
{
throw new NotImplementedException();
}

/** <inheritDoc /> */
public bool testMessagesReceived()
{
throw new NotImplementedException();
}

/** <inheritDoc /> */
public void testSendMessage()
{
throw new NotImplementedException();
}

/** <inheritDoc /> */
public object testRoundtrip(object x)
{
Expand Down
Loading

0 comments on commit 4f7579d

Please sign in to comment.