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

[master] JGroups dependency upgrade plus additonal JUnit tests #1818

Merged
merged 1 commit into from
Feb 22, 2023
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -19,9 +19,11 @@
import org.eclipse.persistence.internal.sessions.coordination.broadcast.BroadcastRemoteConnection;
import org.eclipse.persistence.sessions.coordination.RemoteCommandManager;
import org.eclipse.persistence.sessions.serializers.Serializer;
import org.jgroups.BytesMessage;
import org.jgroups.ObjectMessage;
import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;
import org.jgroups.Receiver;

/**
* <p>
Expand Down Expand Up @@ -52,7 +54,7 @@ public JGroupsRemoteConnection(RemoteCommandManager rcm, JChannel channel, boole
try {
if (isLocalConnectionBeingCreated) {
// it's a local connection
this.channel.setReceiver(new ReceiverAdapter() {
this.channel.setReceiver(new Receiver() {
@Override
public void receive(Message message) {
onMessage(message);
Expand Down Expand Up @@ -93,9 +95,9 @@ public boolean isLocal() {
protected Object executeCommandInternal(Object command) throws Exception {
Message message = null;
if (command instanceof byte[]) {
message = new Message(null, (byte[])command);
message = new BytesMessage(null, (byte[])command);
} else {
message = new Message(null, command);
message = new ObjectMessage(null, command);
}

Object[] debugInfo = null;
Expand Down Expand Up @@ -128,8 +130,8 @@ public void onMessage(Message message) {
Object object = null;
try {
Serializer serializer = this.rcm.getSerializer();
if (serializer != null) {
object = serializer.deserialize(message.getBuffer(), (AbstractSession)this.rcm.getCommandProcessor());
if (message instanceof BytesMessage) {
object = serializer.deserialize(message.getArray(), (AbstractSession)this.rcm.getCommandProcessor());
} else {
object = message.getObject();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// Oracle - Initial implementation
package org.eclipse.persistence.testing.tests.jgroups;

import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.sessions.DatabaseLogin;
import org.eclipse.persistence.sessions.Login;
import org.eclipse.persistence.sessions.coordination.CommandManager;
import org.eclipse.persistence.sessions.coordination.CommandProcessor;

public class JGroupsCommandProcessor extends AbstractSession implements CommandProcessor {

private String commandContent = null;

@Override
public void processCommand(Object command) {
commandContent = command.toString();
}

@Override
public CommandManager getCommandManager() {
return null;
}

@Override
public void setCommandManager(CommandManager commandManager) {

}

@Override
public boolean shouldLogMessages(int logLevel) {
return false;
}

@Override
public void logMessage(int logLevel, String message) {

}

@Override
public void incrementProfile(String counter) {

}

@Override
public void updateProfile(String info, Object value) {

}

@Override
public void startOperationProfile(String operationName) {

}

@Override
public void endOperationProfile(String operationName) {

}

@Override
public Object handleException(RuntimeException exception) {
return null;
}

@Override
public Login getDatasourceLogin() {
Login login = new DatabaseLogin();
return login;
}

public String getCommandContent() {
return commandContent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// Oracle - Initial implementation
package org.eclipse.persistence.testing.tests.jgroups;

import static org.junit.Assert.assertEquals;

import org.eclipse.persistence.internal.sessions.coordination.jgroups.JGroupsRemoteConnection;
import org.eclipse.persistence.sessions.coordination.Command;
import org.eclipse.persistence.sessions.coordination.RemoteCommandManager;
import org.eclipse.persistence.sessions.coordination.ServiceId;
import org.eclipse.persistence.sessions.coordination.TransportManager;

import org.jgroups.JChannel;
import org.jgroups.protocols.pbcast.FLUSH;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

public class JGroupsRemoteConnectionTest {

private final String COMMAND_CONTENT = "testCommand";
private final String CLUSTER_NAME = "ChatCluster";

private JChannel jChannel = null;
private JGroupsRemoteConnection remoteConnection = null;
private JGroupsCommandProcessor commandProcessor = null;

@Before
public void init() throws Exception {
commandProcessor = new JGroupsCommandProcessor();
RemoteCommandManager remoteCommandManager = new RemoteCommandManager(commandProcessor);
TransportManager senderTransportManager = new JGroupsTestTransportManager();
remoteCommandManager.setTransportManager(senderTransportManager);
jChannel = new JChannel();
jChannel.getProtocolStack().addProtocol(new FLUSH());
remoteConnection = new JGroupsRemoteConnection(remoteCommandManager, jChannel, true);
jChannel.connect(CLUSTER_NAME);
}

@After
public void shutdown() throws Exception {
remoteConnection.close();
jChannel.close();
}

/**
* Test JGroupsRemoteConnection with Command passed as a Object.
*/
@Test
public void testObjectCommand() throws Exception {
ServiceId serviceId = new ServiceId();
serviceId.setChannel(RemoteCommandManager.DEFAULT_CHANNEL);
Command testCommand = new JGroupsTestCommand(serviceId, COMMAND_CONTENT);
jChannel.connect(CLUSTER_NAME);
remoteConnection.executeCommand(testCommand);
jChannel.startFlush(true);
assertEquals(COMMAND_CONTENT, commandProcessor.getCommandContent());
}

/**
* Test JGroupsRemoteConnection with Command passed as an array of bytes.
*/
@Test
public void testByteArrayCommand() throws Exception {
ServiceId serviceId = new ServiceId();
serviceId.setChannel(RemoteCommandManager.DEFAULT_CHANNEL);
Command testCommand = new JGroupsTestCommand(serviceId, COMMAND_CONTENT);
byte[] testCommandSerialized = serializeCommand(testCommand);
jChannel.connect(CLUSTER_NAME);
remoteConnection.executeCommand(testCommandSerialized);
jChannel.startFlush(true);
assertEquals(COMMAND_CONTENT, commandProcessor.getCommandContent());
}

private byte[] serializeCommand(Command command) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = null;
byte[] result = null;
try {
out = new ObjectOutputStream(bos);
out.writeObject(command);
out.flush();
result = bos.toByteArray();
bos.close();
} catch (IOException ex) {
// ignore exception
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// Oracle - Initial implementation
package org.eclipse.persistence.testing.tests.jgroups;

import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.sessions.coordination.Command;
import org.eclipse.persistence.sessions.coordination.ServiceId;

public class JGroupsTestCommand extends Command {

private String commmand = null;

public JGroupsTestCommand(ServiceId serviceId, String commmand) {
this.setServiceId(serviceId);
this.commmand = commmand;
}

@Override
public void executeWithSession(AbstractSession session) {
session.logMessage("Command: " + commmand);
}

@Override
public String toString() {
return commmand;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// Oracle - Initial implementation
package org.eclipse.persistence.testing.tests.jgroups;

import org.eclipse.persistence.sessions.coordination.broadcast.BroadcastTransportManager;

public class JGroupsTestTransportManager extends BroadcastTransportManager {

@Override
public void createLocalConnection() {
}

@Override
public void removeLocalConnection() {
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
<hibernate.version>8.0.0.Final</hibernate.version>
<checkstyle.version>10.7.0</checkstyle.version>
<!-- CQ #23049 -->
<jgroups.version>4.2.11.Final</jgroups.version>
<jgroups.version>5.2.12.Final</jgroups.version>
<jmh.version>1.36</jmh.version>
<junit.version>4.13.2</junit.version>
<!-- CQ #24079 -->
Expand Down