Skip to content

Commit

Permalink
IGNITE-12177 Java compute tasks for C++
Browse files Browse the repository at this point in the history
This closes apache#9312
  • Loading branch information
isapego committed Aug 12, 2021
1 parent c7a835f commit c51e278
Show file tree
Hide file tree
Showing 29 changed files with 2,160 additions and 903 deletions.
1,454 changes: 721 additions & 733 deletions .idea/inspectionProfiles/Project_Default.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.ignite.Ignite;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.compute.ComputeJob;
import org.apache.ignite.compute.ComputeJobAdapter;
import org.apache.ignite.compute.ComputeJobResult;
import org.apache.ignite.compute.ComputeTaskAdapter;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Test task returning Node name.
*/
public class PlatformComputeNodeNameTask extends ComputeTaskAdapter<Object, Object> {
/** {@inheritDoc} */
@NotNull @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
@Nullable Object arg) {
return Collections.singletonMap(new Job(), F.rand(subgrid));
}

/** {@inheritDoc} */
@Nullable @Override public Object reduce(List<ComputeJobResult> results) {
return results.get(0).getData();
}

/**
* Job.
*/
private static class Job extends ComputeJobAdapter {
/** Ignite. */
@IgniteInstanceResource
private Ignite ignite;

/** {@inheritDoc} */
@Nullable @Override public Object execute() {
return ignite.name();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,25 @@ namespace ignite

/** Flag: acquired. */
const int IGNITE_MEM_FLAG_ACQUIRED = 0x4;


/**
* A helper union to bitwise conversion from int32_t to float and back.
*/
union BinaryFloatInt32
{
float f;
int32_t i;
};

/**
* A helper union to bitwise conversion from int64_t to double and back.
*/
union BinaryDoubleInt64
{
double d;
int64_t i;
};

/**
* Interop memory.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ namespace ignite
{
namespace interop
{
union BinaryInt32Float
{
int32_t i;
float f;
};

union BinaryInt64Double
{
int64_t i;
double d;
};

InteropInputStream::InteropInputStream(InteropMemory* mem)
{
this->mem = mem;
Expand Down Expand Up @@ -158,7 +146,7 @@ namespace ignite

float InteropInputStream::ReadFloat()
{
BinaryInt32Float u;
BinaryFloatInt32 u;

u.i = ReadInt32();

Expand All @@ -172,7 +160,7 @@ namespace ignite

double InteropInputStream::ReadDouble()
{
BinaryInt64Double u;
BinaryDoubleInt64 u;

u.i = ReadInt64();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ namespace ignite
{
namespace interop
{
union BinaryFloatInt32
{
float f;
int32_t i;
};

union BinaryDoubleInt64
{
double d;
int64_t i;
};

InteropOutputStream::InteropOutputStream(InteropMemory* mem)
{
this->mem = mem;
Expand Down
1 change: 1 addition & 0 deletions modules/platforms/cpp/core-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(SOURCES src/reference_test.cpp
src/continuous_query_test.cpp
src/concurrent_test.cpp
src/compute_test.cpp
src/compute_java_test.cpp
src/ignition_test.cpp
src/interop_memory_test.cpp
src/interop_test.cpp
Expand Down
6 changes: 3 additions & 3 deletions modules/platforms/cpp/core-test/include/ignite/complex_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

#ifndef _IGNITE_ODBC_TEST_COMPLEX_TYPE
#define _IGNITE_ODBC_TEST_COMPLEX_TYPE
#ifndef _IGNITE_CORE_TEST_COMPLEX_TYPE
#define _IGNITE_CORE_TEST_COMPLEX_TYPE

#include <stdint.h>
#include <string>
Expand Down Expand Up @@ -120,4 +120,4 @@ namespace ignite
}
}

#endif // _IGNITE_ODBC_TEST_COMPLEX_TYPE
#endif // _IGNITE_CORE_TEST_COMPLEX_TYPE
81 changes: 81 additions & 0 deletions modules/platforms/cpp/core-test/include/ignite/compute_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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.
*/

#ifndef _IGNITE_CORE_TEST_COMPUTE_TYPES
#define _IGNITE_CORE_TEST_COMPUTE_TYPES

#include <stdint.h>
#include <string>

#include <ignite/ignite_predicate.h>
#include <ignite/cluster/cluster_node.h>

namespace ignite_test
{
/*
* Check if cluster node contains an attribute with name provided.
*/
class HasAttrName : public ignite::IgnitePredicate<ignite::cluster::ClusterNode>
{
public:
HasAttrName(std::string name) :
name(name)
{
// No-op.
}

bool operator()(ignite::cluster::ClusterNode& node)
{
std::vector<std::string> attrs = node.GetAttributes();

return std::find(attrs.begin(), attrs.end(), name) != attrs.end();
}

private:
std::string name;
};

/*
* Check if cluster node contains an attribute with value provided.
*/
class HasAttrValue : public ignite::IgnitePredicate<ignite::cluster::ClusterNode>
{
public:
HasAttrValue(std::string name, std::string val) :
name(name),
val(val)
{
// No-op.
}

bool operator()(ignite::cluster::ClusterNode& node)
{
try {
return node.GetAttribute<std::string>(name) == this->val;
}
catch (...) {}

return false;
}

private:
std::string name;
std::string val;
};
}

#endif // _IGNITE_CORE_TEST_COMPUTE_TYPES
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<ClInclude Include="..\..\include\ignite\binary_test_defs.h" />
<ClInclude Include="..\..\include\ignite\binary_test_utils.h" />
<ClInclude Include="..\..\include\ignite\complex_type.h" />
<ClInclude Include="..\..\include\ignite\compute_types.h" />
<ClInclude Include="..\..\include\ignite\test_type.h" />
<ClInclude Include="..\..\include\ignite\test_utils.h" />
<ClInclude Include="..\..\include\teamcity_messages.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
<ClCompile Include="..\..\src\compute_test.cpp">
<Filter>Code</Filter>
</ClCompile>
<ClCompile Include="..\..\src\compute_java_test.cpp">
<Filter>Code</Filter>
</ClCompile>
<ClCompile Include="..\..\src\compute_java_test.cpp">
<Filter>Code</Filter>
</ClCompile>
<ClCompile Include="..\..\src\cluster_group_test.cpp">
<Filter>Code</Filter>
</ClCompile>
Expand All @@ -111,6 +117,9 @@
<ClInclude Include="..\..\include\ignite\complex_type.h">
<Filter>Code\Types</Filter>
</ClInclude>
<ClInclude Include="..\..\include\ignite\compute_types.h">
<Filter>Code\Types</Filter>
</ClInclude>
<ClInclude Include="..\..\include\ignite\test_type.h">
<Filter>Code\Types</Filter>
</ClInclude>
Expand Down
65 changes: 8 additions & 57 deletions modules/platforms/cpp/core-test/src/cluster_group_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <ignite/ignition.h>
#include <ignite/test_utils.h>
#include <ignite/compute_types.h>

using namespace ignite;
using namespace ignite::common;
Expand All @@ -27,56 +28,6 @@ using namespace ignite::cluster;

using namespace boost::unit_test;

/*
* Check if cluster node contain the attribute with name provided.
*/
class HasAttrName : public IgnitePredicate<ClusterNode>
{
public:
HasAttrName(std::string name) :
name(name)
{
// No-op.
}

bool operator()(ClusterNode& node)
{
std::vector<std::string> attrs = node.GetAttributes();

return std::find(attrs.begin(), attrs.end(), name) != attrs.end();
}

private:
std::string name;
};

/*
* Check if cluster node contain the attribute with value provided.
*/
class HasAttrValue : public IgnitePredicate<ClusterNode>
{
public:
HasAttrValue(std::string name, std::string val) :
name(name), val(val)
{
// No-op.
}

bool operator()(ClusterNode& node)
{
try {
return node.GetAttribute<std::string>(name) == this->val;
}
catch (...) {}

return false;
}

private:
std::string name;
std::string val;
};

/*
* Predicate holder is required to demonstrate
* how to pass IgnitePredicate pointer to the stl container.
Expand Down Expand Up @@ -397,8 +348,8 @@ BOOST_AUTO_TEST_CASE(IgniteForPredicate)

ClusterGroup groupServers = group0.ForServers();
ClusterGroup groupClients = group0.ForClients();
ClusterGroup group1 = groupServers.ForPredicate(new HasAttrValue("TestAttribute", "Value0"));
ClusterGroup group2 = groupServers.ForPredicate(new HasAttrValue("TestAttribute", "Value1"));
ClusterGroup group1 = groupServers.ForPredicate(new ignite_test::HasAttrValue("TestAttribute", "Value0"));
ClusterGroup group2 = groupServers.ForPredicate(new ignite_test::HasAttrValue("TestAttribute", "Value1"));
ClusterGroup group3 = groupServers.ForClients();

BOOST_REQUIRE(group0.GetNodes().size() == 4);
Expand All @@ -408,10 +359,10 @@ BOOST_AUTO_TEST_CASE(IgniteForPredicate)
BOOST_REQUIRE(group2.GetNodes().size() == 2);
BOOST_REQUIRE(group3.GetNodes().size() == 0);

ClusterGroup group4 = group0.ForPredicate(new HasAttrName("TestAttribute"));
ClusterGroup group5 = group4.ForPredicate(new HasAttrValue("TestAttribute", "Value0"));
ClusterGroup group6 = group4.ForPredicate(new HasAttrValue("TestAttribute", "Value1"));
ClusterGroup group7 = group4.ForPredicate(new HasAttrValue("TestAttribute", "ValueInvalid"));
ClusterGroup group4 = group0.ForPredicate(new ignite_test::HasAttrName("TestAttribute"));
ClusterGroup group5 = group4.ForPredicate(new ignite_test::HasAttrValue("TestAttribute", "Value0"));
ClusterGroup group6 = group4.ForPredicate(new ignite_test::HasAttrValue("TestAttribute", "Value1"));
ClusterGroup group7 = group4.ForPredicate(new ignite_test::HasAttrValue("TestAttribute", "ValueInvalid"));

BOOST_REQUIRE(group4.GetNodes().size() == 3);
BOOST_REQUIRE(group5.GetNodes().size() == 1);
Expand Down Expand Up @@ -534,7 +485,7 @@ BOOST_AUTO_TEST_CASE(IgniteGetPredicate)
{
IgniteCluster cluster = server1.GetCluster();
ClusterGroup group0 = cluster.AsClusterGroup();
ClusterGroup group1 = group0.ForPredicate(new HasAttrValue("TestAttribute", "Value1"));
ClusterGroup group1 = group0.ForPredicate(new ignite_test::HasAttrValue("TestAttribute", "Value1"));

std::vector<ClusterNode> nodes0 = group0.GetNodes();
std::vector<ClusterNode> nodes1 = group1.GetNodes();
Expand Down
Loading

0 comments on commit c51e278

Please sign in to comment.