Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Connecting and additional tests #682

Merged
merged 2 commits into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/org/java_websocket/WebSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ enum Role {
* Enum which represents the state a websocket may be in
*/
enum READYSTATE {
NOT_YET_CONNECTED, CONNECTING, OPEN, CLOSING, CLOSED
NOT_YET_CONNECTED,
@Deprecated
CONNECTING, OPEN, CLOSING, CLOSED
}

/**
Expand Down Expand Up @@ -172,6 +174,7 @@ enum READYSTATE {
* Is the websocket in the state CONNECTING
* @return state equals READYSTATE.CONNECTING
*/
@Deprecated
boolean isConnecting();

/**
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/java_websocket/WebSocketImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,6 @@ public boolean hasBufferedData() {
}

public void startHandshake( ClientHandshakeBuilder handshakedata ) throws InvalidHandshakeException {
assert ( getReadyState() != READYSTATE.CONNECTING ) : "shall only be called once";

// Store the Handshake Request we are about to send
this.handshakerequest = draft.postProcessHandshakeRequestAsClient( handshakedata );

Expand Down Expand Up @@ -710,6 +708,7 @@ private void open( Handshakedata d ) {
}

@Override
@Deprecated
public boolean isConnecting() {
assert ( !flushandclosestate || getReadyState() == READYSTATE.CONNECTING );
return getReadyState() == READYSTATE.CONNECTING; // ifflushandclosestate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ public boolean isClosing() {
}

@Override
@Deprecated
public boolean isConnecting() {
return engine.isConnecting();
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/java_websocket/issues/AllIssueTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
org.java_websocket.issues.Issue580Test.class,
org.java_websocket.issues.Issue256Test.class,
org.java_websocket.issues.Issue661Test.class,
org.java_websocket.issues.Issue666Test.class
org.java_websocket.issues.Issue666Test.class,
org.java_websocket.issues.Issue677Test.class
})
/**
* Start all tests for issues
Expand Down
128 changes: 128 additions & 0 deletions src/test/java/org/java_websocket/issues/Issue677Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright (c) 2010-2018 Nathan Rajlich
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

package org.java_websocket.issues;

import org.java_websocket.WebSocket;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.framing.CloseFrame;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.handshake.ServerHandshake;
import org.java_websocket.server.WebSocketServer;
import org.java_websocket.util.SocketUtil;
import org.junit.Test;

import java.net.InetSocketAddress;
import java.net.URI;
import java.util.concurrent.CountDownLatch;

import static org.junit.Assert.assertTrue;

public class Issue677Test {

CountDownLatch countDownLatch0 = new CountDownLatch( 1 );
CountDownLatch countServerDownLatch = new CountDownLatch( 1 );

@Test
public void testIssue() throws Exception {
int port = SocketUtil.getAvailablePort();
WebSocketClient webSocket0 = new WebSocketClient( new URI( "ws://localhost:" + port ) ) {
@Override
public void onOpen( ServerHandshake handshakedata ) {

}

@Override
public void onMessage( String message ) {

}

@Override
public void onClose( int code, String reason, boolean remote ) {
countDownLatch0.countDown();
}

@Override
public void onError( Exception ex ) {

}
};
WebSocketClient webSocket1 = new WebSocketClient( new URI( "ws://localhost:" + port ) ) {
@Override
public void onOpen( ServerHandshake handshakedata ) {
}

@Override
public void onMessage( String message ) {
}

@Override
public void onClose( int code, String reason, boolean remote ) {
}

@Override
public void onError( Exception ex ) {

}
};
WebSocketServer server = new WebSocketServer( new InetSocketAddress( port ) ) {
@Override
public void onOpen( WebSocket conn, ClientHandshake handshake ) {
}

@Override
public void onClose( WebSocket conn, int code, String reason, boolean remote ) {
}

@Override
public void onMessage( WebSocket conn, String message ) {

}

@Override
public void onError( WebSocket conn, Exception ex ) {

}

@Override
public void onStart() {
countServerDownLatch.countDown();
}
};
server.start();
countServerDownLatch.await();
webSocket0.connectBlocking();
assertTrue( "webSocket.isOpen()", webSocket0.isOpen() );
webSocket0.close();
assertTrue( "webSocket.isClosing()", webSocket0.isClosing() );
countDownLatch0.await();
assertTrue( "webSocket.isClosed()", webSocket0.isClosed() );
webSocket1.connectBlocking();
assertTrue( "webSocket.isOpen()", webSocket1.isOpen() );
webSocket1.closeConnection(CloseFrame.ABNORMAL_CLOSE, "Abnormal close!");
assertTrue( "webSocket.isClosed()", webSocket1.isClosed() );
server.stop();
}
}