Search in sources :

Example 1 with ModbusTCPSlaveEndpoint

use of org.openhab.binding.modbus.internal.pooling.ModbusTCPSlaveEndpoint in project openhab1-addons by openhab.

the class ModbusSlaveEndpointTestCase method testEqualsSameTcp.

@Test
public void testEqualsSameTcp() {
    ModbusTCPSlaveEndpoint e1 = new ModbusTCPSlaveEndpoint("127.0.0.1", 500);
    ModbusTCPSlaveEndpoint e2 = new ModbusTCPSlaveEndpoint("127.0.0.1", 500);
    Assert.assertEquals(e1, e2);
}
Also used : ModbusTCPSlaveEndpoint(org.openhab.binding.modbus.internal.pooling.ModbusTCPSlaveEndpoint) Test(org.junit.Test)

Example 2 with ModbusTCPSlaveEndpoint

use of org.openhab.binding.modbus.internal.pooling.ModbusTCPSlaveEndpoint in project openhab1-addons by openhab.

the class ModbusSlaveEndpointTestCase method testEqualsDifferentTCPPort.

@Test
public void testEqualsDifferentTCPPort() {
    ModbusTCPSlaveEndpoint e1 = new ModbusTCPSlaveEndpoint("127.0.0.1", 500);
    ModbusTCPSlaveEndpoint e2 = new ModbusTCPSlaveEndpoint("127.0.0.1", 501);
    Assert.assertNotEquals(e1, e2);
    Assert.assertNotEquals(e1.hashCode(), e2.hashCode());
}
Also used : ModbusTCPSlaveEndpoint(org.openhab.binding.modbus.internal.pooling.ModbusTCPSlaveEndpoint) Test(org.junit.Test)

Example 3 with ModbusTCPSlaveEndpoint

use of org.openhab.binding.modbus.internal.pooling.ModbusTCPSlaveEndpoint in project openhab1-addons by openhab.

the class ModbusSlaveEndpointTestCase method testEqualsDifferentProtocol.

@Test
public void testEqualsDifferentProtocol() {
    ModbusTCPSlaveEndpoint e1 = new ModbusTCPSlaveEndpoint("127.0.0.1", 500);
    ModbusUDPSlaveEndpoint e2 = new ModbusUDPSlaveEndpoint("127.0.0.1", 500);
    Assert.assertNotEquals(e1, e2);
    Assert.assertNotEquals(e1.hashCode(), e2.hashCode());
}
Also used : ModbusUDPSlaveEndpoint(org.openhab.binding.modbus.internal.pooling.ModbusUDPSlaveEndpoint) ModbusTCPSlaveEndpoint(org.openhab.binding.modbus.internal.pooling.ModbusTCPSlaveEndpoint) Test(org.junit.Test)

Example 4 with ModbusTCPSlaveEndpoint

use of org.openhab.binding.modbus.internal.pooling.ModbusTCPSlaveEndpoint in project openhab1-addons by openhab.

the class ModbusSlaveEndpointTestCase method testEqualsDifferentProtocol2.

@Test
public void testEqualsDifferentProtocol2() {
    ModbusTCPSlaveEndpoint e1 = new ModbusTCPSlaveEndpoint("127.0.0.1", 500);
    ModbusSerialSlaveEndpoint e2 = new ModbusSerialSlaveEndpoint(new SerialParameters());
    Assert.assertNotEquals(e1, e2);
    Assert.assertNotEquals(e1.hashCode(), e2.hashCode());
}
Also used : ModbusSerialSlaveEndpoint(org.openhab.binding.modbus.internal.pooling.ModbusSerialSlaveEndpoint) ModbusTCPSlaveEndpoint(org.openhab.binding.modbus.internal.pooling.ModbusTCPSlaveEndpoint) SerialParameters(net.wimpi.modbus.util.SerialParameters) Test(org.junit.Test)

Example 5 with ModbusTCPSlaveEndpoint

use of org.openhab.binding.modbus.internal.pooling.ModbusTCPSlaveEndpoint in project openhab1-addons by openhab.

the class SimultaneousReadWriteTestCase method testPoolBlocks.

@Test
public void testPoolBlocks() throws Exception {
    final KeyedObjectPool<ModbusSlaveEndpoint, ModbusSlaveConnection> pool = ModbusBinding.getReconstructedConnectionPoolForTesting();
    final ModbusTCPSlaveEndpoint endpoint = new ModbusTCPSlaveEndpoint(localAddress().getHostAddress(), this.tcpModbusPort);
    ModbusSlaveConnection borrowObject = pool.borrowObject(endpoint);
    Thread thread = new Thread() {

        @Override
        public void run() {
            try {
                ModbusSlaveConnection borrowObject2 = pool.borrowObject(endpoint);
                pool.returnObject(endpoint, borrowObject2);
            } catch (Exception e) {
                e.printStackTrace(System.err);
            }
        }
    };
    thread.start();
    thread.join(500);
    if (!thread.isAlive()) {
        throw new AssertionError("Thread should still be alive -- blocking since no objects");
    } else {
        thread.interrupt();
    }
    pool.returnObject(endpoint, borrowObject);
    // Now that object has been returned, borrowing should work again
    ModbusSlaveConnection borrowObject2 = pool.borrowObject(endpoint);
    pool.returnObject(endpoint, borrowObject2);
}
Also used : ModbusSlaveEndpoint(org.openhab.binding.modbus.internal.pooling.ModbusSlaveEndpoint) ModbusTCPSlaveEndpoint(org.openhab.binding.modbus.internal.pooling.ModbusTCPSlaveEndpoint) ModbusSlaveConnection(net.wimpi.modbus.net.ModbusSlaveConnection) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ModbusTCPSlaveEndpoint (org.openhab.binding.modbus.internal.pooling.ModbusTCPSlaveEndpoint)6 ModbusSlaveConnection (net.wimpi.modbus.net.ModbusSlaveConnection)1 SerialParameters (net.wimpi.modbus.util.SerialParameters)1 ModbusSerialSlaveEndpoint (org.openhab.binding.modbus.internal.pooling.ModbusSerialSlaveEndpoint)1 ModbusSlaveEndpoint (org.openhab.binding.modbus.internal.pooling.ModbusSlaveEndpoint)1 ModbusUDPSlaveEndpoint (org.openhab.binding.modbus.internal.pooling.ModbusUDPSlaveEndpoint)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1