-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plc4j): Fix bug with select returning prematurely when device not…
… sending any data (#386) * Add support for custom handlers used in testing * Add support for custom handlers used in testing * Add test to demonstrate problem with current select() implementation * Change select() and wakeup() logic to match API expectations * Don't use Java 11 features as PR check build fails * Fix missing import * Add missing headers * Declare dependency used by the new test
- Loading branch information
Showing
9 changed files
with
331 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
.../transports/serial/src/test/java/org/apache/plc4x/java/transport/serial/DummyHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* 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 | ||
* | ||
* https://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.plc4x.java.transport.serial; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
|
||
import java.net.SocketAddress; | ||
|
||
public class DummyHandler extends SerialChannelHandler { | ||
|
||
public static final DummyHandler INSTANCE = new DummyHandler(null); | ||
|
||
private SerialSelectionKey selectionKey; | ||
|
||
public DummyHandler(SocketAddress address) { | ||
super(address); | ||
} | ||
|
||
@Override | ||
public boolean open() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getIdentifier() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void registerSelectionKey(SerialSelectionKey selectionKey) { | ||
this.selectionKey = selectionKey; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// NOOP | ||
} | ||
|
||
@Override | ||
public int read(ByteBuf buf) { | ||
buf.writeByte(1); | ||
return 1; | ||
} | ||
|
||
@Override | ||
public int write(ByteBuf buf) { | ||
System.out.println("Haha i wrote something"); | ||
return 1; | ||
} | ||
|
||
public void fireEvent(int readyOp) { | ||
((SerialPollingSelector) this.selectionKey.selector()) | ||
.addEvent(new SerialPollingSelector.SelectorEvent(this.selectionKey, readyOp)); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...serial/src/test/java/org/apache/plc4x/java/transport/serial/IdleSerialChannelHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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 | ||
* | ||
* https://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.plc4x.java.transport.serial; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
|
||
class IdleSerialChannelHandler extends SerialChannelHandler { | ||
|
||
public IdleSerialChannelHandler() { | ||
super(null); | ||
} | ||
|
||
@Override | ||
public boolean open() { | ||
return true; | ||
} | ||
|
||
@Override | ||
String getIdentifier() { | ||
return "Emulated Com Port"; | ||
} | ||
|
||
@Override | ||
void registerSelectionKey(SerialSelectionKey selectionKey) { | ||
/* | ||
* We can ignore registration as we will neven trigger events | ||
*/ | ||
} | ||
|
||
@Override | ||
public void close() { | ||
} | ||
|
||
@Override | ||
public int read(ByteBuf buf) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int write(ByteBuf buf) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
Oops, something went wrong.