Skip to content

Commit b598254

Browse files
ptupitsynisapego
authored andcommitted
GG-25632 Python Thin - Extend test coverage [NBL-5] Python thin client: best effort affinity (#3)
1 parent 0f7893d commit b598254

20 files changed

Lines changed: 1101 additions & 64 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
.idea
2+
.eggs
3+
.pytest_cache
4+
pygridgain.egg-info
5+
ignite-log-*

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,4 @@ Run
9191
```
9292
$ cd gridgain/modules/platforms/python
9393
$ python setup.py pytest
94-
```
95-
96-
*NB!* All tests require GridGain node running on localhost:10800.
97-
If you need to change the connection parameters, see the documentation on
98-
[testing](https://pygridgain.readthedocs.io/en/latest/readme.html#testing).
94+
```

pygridgain/cache.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ def get_best_node(
257257
if key_hint is None:
258258
key_hint = AnyDataObject.map_python_type(key)
259259

260+
parts = -1
261+
260262
if self.affinity['version'] < self._client.affinity_version:
261263
# update partition mapping
262264
while True:
@@ -284,7 +286,10 @@ def get_best_node(
284286
self.affinity['number_of_partitions'] = parts
285287
else:
286288
# get number of partitions
287-
parts = self.affinity['number_of_partitions']
289+
parts = self.affinity.get('number_of_partitions')
290+
291+
if not parts:
292+
return conn
288293

289294
if self.affinity['is_applicable']:
290295
affinity_key_id = self.affinity['cache_config'].get(

requirements/tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
pytest==3.6.1
44
pytest-cov==2.5.1
55
teamcity-messages==1.21
6+
psutil==5.6.5

tests/config/ignite-config-1.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Copyright 2019 GridGain Systems, Inc. and Contributors.
5+
6+
Licensed under the GridGain Community Edition License (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<beans xmlns="http://www.springframework.org/schema/beans"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xmlns:util="http://www.springframework.org/schema/util"
22+
xsi:schemaLocation="
23+
http://www.springframework.org/schema/beans
24+
http://www.springframework.org/schema/beans/spring-beans.xsd
25+
http://www.springframework.org/schema/util
26+
http://www.springframework.org/schema/util/spring-util.xsd">
27+
<import resource="ignite-config-base.xml"/>
28+
29+
<bean parent="grid.cfg">
30+
<property name="clientConnectorConfiguration">
31+
<bean class="org.apache.ignite.configuration.ClientConnectorConfiguration">
32+
<property name="host" value="127.0.0.1"/>
33+
<property name="port" value="10801"/>
34+
<property name="portRange" value="0"/>
35+
</bean>
36+
</property>
37+
38+
<property name="gridLogger">
39+
<bean class="org.apache.ignite.logger.log4j.Log4JLogger">
40+
<constructor-arg type="java.lang.String" value="config/log4j-1.xml"/>
41+
</bean>
42+
</property>
43+
</bean>
44+
</beans>

tests/config/ignite-config-2.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Copyright 2019 GridGain Systems, Inc. and Contributors.
5+
6+
Licensed under the GridGain Community Edition License (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<beans xmlns="http://www.springframework.org/schema/beans"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xmlns:util="http://www.springframework.org/schema/util"
22+
xsi:schemaLocation="
23+
http://www.springframework.org/schema/beans
24+
http://www.springframework.org/schema/beans/spring-beans.xsd
25+
http://www.springframework.org/schema/util
26+
http://www.springframework.org/schema/util/spring-util.xsd">
27+
<import resource="ignite-config-base.xml"/>
28+
29+
<bean parent="grid.cfg">
30+
<property name="clientConnectorConfiguration">
31+
<bean class="org.apache.ignite.configuration.ClientConnectorConfiguration">
32+
<property name="host" value="127.0.0.1"/>
33+
<property name="port" value="10802"/>
34+
<property name="portRange" value="0"/>
35+
</bean>
36+
</property>
37+
38+
<property name="gridLogger">
39+
<bean class="org.apache.ignite.logger.log4j.Log4JLogger">
40+
<constructor-arg type="java.lang.String" value="config/log4j-2.xml"/>
41+
</bean>
42+
</property>
43+
</bean>
44+
</beans>

tests/config/ignite-config-3.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Copyright 2019 GridGain Systems, Inc. and Contributors.
5+
6+
Licensed under the GridGain Community Edition License (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<beans xmlns="http://www.springframework.org/schema/beans"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xmlns:util="http://www.springframework.org/schema/util"
22+
xsi:schemaLocation="
23+
http://www.springframework.org/schema/beans
24+
http://www.springframework.org/schema/beans/spring-beans.xsd
25+
http://www.springframework.org/schema/util
26+
http://www.springframework.org/schema/util/spring-util.xsd">
27+
<import resource="ignite-config-base.xml"/>
28+
29+
<bean parent="grid.cfg">
30+
<property name="clientConnectorConfiguration">
31+
<bean class="org.apache.ignite.configuration.ClientConnectorConfiguration">
32+
<property name="host" value="127.0.0.1"/>
33+
<property name="port" value="10803"/>
34+
<property name="portRange" value="0"/>
35+
</bean>
36+
</property>
37+
38+
<property name="gridLogger">
39+
<bean class="org.apache.ignite.logger.log4j.Log4JLogger">
40+
<constructor-arg type="java.lang.String" value="config/log4j-3.xml"/>
41+
</bean>
42+
</property>
43+
</bean>
44+
</beans>

tests/config/ignite-config-4.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Copyright 2019 GridGain Systems, Inc. and Contributors.
5+
6+
Licensed under the GridGain Community Edition License (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<beans xmlns="http://www.springframework.org/schema/beans"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xmlns:util="http://www.springframework.org/schema/util"
22+
xsi:schemaLocation="
23+
http://www.springframework.org/schema/beans
24+
http://www.springframework.org/schema/beans/spring-beans.xsd
25+
http://www.springframework.org/schema/util
26+
http://www.springframework.org/schema/util/spring-util.xsd">
27+
<import resource="ignite-config-base.xml"/>
28+
29+
<bean parent="grid.cfg">
30+
<property name="clientConnectorConfiguration">
31+
<bean class="org.apache.ignite.configuration.ClientConnectorConfiguration">
32+
<property name="host" value="127.0.0.1"/>
33+
<property name="port" value="10804"/>
34+
<property name="portRange" value="0"/>
35+
</bean>
36+
</property>
37+
38+
<property name="gridLogger">
39+
<bean class="org.apache.ignite.logger.log4j.Log4JLogger">
40+
<constructor-arg type="java.lang.String" value="config/log4j-4.xml"/>
41+
</bean>
42+
</property>
43+
</bean>
44+
</beans>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Copyright 2019 GridGain Systems, Inc. and Contributors.
5+
6+
Licensed under the GridGain Community Edition License (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<beans xmlns="http://www.springframework.org/schema/beans"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xmlns:util="http://www.springframework.org/schema/util"
22+
xsi:schemaLocation="
23+
http://www.springframework.org/schema/beans
24+
http://www.springframework.org/schema/beans/spring-beans.xsd
25+
http://www.springframework.org/schema/util
26+
http://www.springframework.org/schema/util/spring-util.xsd">
27+
<bean id="grid.cfg" abstract="true" class="org.apache.ignite.configuration.IgniteConfiguration">
28+
<property name="localHost" value="127.0.0.1"/>
29+
30+
<property name="discoverySpi">
31+
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
32+
<property name="localAddress" value="127.0.0.1"/>
33+
<property name="localPort" value="48500"/>
34+
<property name="ipFinder">
35+
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
36+
<property name="addresses">
37+
<list>
38+
<value>127.0.0.1:48500..48503</value>
39+
</list>
40+
</property>
41+
</bean>
42+
</property>
43+
<property name="socketTimeout" value="300"/>
44+
</bean>
45+
</property>
46+
47+
<property name="communicationSpi">
48+
<bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi">
49+
<property name="localAddress" value="127.0.0.1"/>
50+
<property name="localPort" value="48100"/>
51+
</bean>
52+
</property>
53+
54+
<property name="cacheConfiguration">
55+
<list>
56+
<bean class="org.apache.ignite.configuration.CacheConfiguration">
57+
<property name="name" value="custom-affinity"/>
58+
<property name="affinity">
59+
<bean class="org.apache.ignite.internal.processors.affinity.LocalAffinityFunction"/>
60+
</property>
61+
</bean>
62+
</list>
63+
</property>
64+
</bean>
65+
</beans>

tests/config/log4j-1.xml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Copyright 2019 GridGain Systems, Inc. and Contributors.
5+
6+
Licensed under the GridGain Community Edition License (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN"
20+
"http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
21+
22+
<!--
23+
Default log4j configuration for Ignite.
24+
-->
25+
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
26+
27+
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
28+
<param name="Target" value="System.out"/>
29+
<param name="Threshold" value="Debug"/>
30+
<layout class="org.apache.log4j.PatternLayout">
31+
<param name="ConversionPattern" value="[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"/>
32+
</layout>
33+
</appender>
34+
35+
<appender name="FILE" class="org.apache.ignite.logger.log4j.Log4jRollingFileAppender">
36+
<param name="Threshold" value="DEBUG"/>
37+
<param name="File" value="logs/ignite-log-1.txt"/>
38+
<param name="Append" value="true"/>
39+
<param name="MaxFileSize" value="10MB"/>
40+
<param name="MaxBackupIndex" value="10"/>
41+
<layout class="org.apache.log4j.PatternLayout">
42+
<param name="ConversionPattern" value="%m%n"/>
43+
</layout>
44+
</appender>
45+
46+
<category name="org.apache.ignite.internal.processors.odbc.ClientListenerNioListener">
47+
<level value="DEBUG"/>
48+
</category>
49+
50+
<!-- Default settings. -->
51+
<root>
52+
<!-- Print out all info by default. -->
53+
<level value="INFO"/>
54+
55+
<appender-ref ref="CONSOLE"/>
56+
<appender-ref ref="FILE"/>
57+
</root>
58+
</log4j:configuration>

0 commit comments

Comments
 (0)