/** * Test parsing messages with version differences between the message and the protocol for the * change to add the jeVersion field to the RepNodeImpl class. */ @Test public void testJEVersionVersioning() throws InvalidMessageException { /* New group format with JE version and new node types */ final RepNodeImpl newNode = new RepNodeImpl( new NameIdPair("m1", 1), NodeType.MONITOR, "localhost", 5000, JEVersion.CURRENT_VERSION); final RepNodeImpl secondaryNode = new RepNodeImpl( new NameIdPair("s1", 2), NodeType.SECONDARY, "localhost", 5001, JEVersion.CURRENT_VERSION); final RepGroupImpl newGroup = new RepGroupImpl(GROUP_NAME, null); final Map<Integer, RepNodeImpl> nodeMap = new HashMap<Integer, RepNodeImpl>(); nodeMap.put(1, newNode); nodeMap.put(2, secondaryNode); newGroup.setNodes(nodeMap); /* Old protocol using RepGroupImpl version 2 */ final Protocol oldProtocol = new Protocol( Protocol.REP_GROUP_V2_VERSION, GROUP_NAME, new NameIdPair(NODE_NAME, 1), null, channelFactory); /* Old group format with no JE version or new node types */ final RepNodeImpl oldNode = new RepNodeImpl(new NameIdPair("m1", 1), NodeType.MONITOR, "localhost", 5000, null); final RepGroupImpl oldGroup = new RepGroupImpl(GROUP_NAME, newGroup.getUUID(), RepGroupImpl.FORMAT_VERSION_2); oldGroup.setNodes(Collections.singletonMap(1, oldNode)); /* Old message format, using new group format, to check conversion */ final GroupChange oldGroupChange = oldProtocol.new GroupChange(newGroup, NODE_NAME, GroupChangeType.ADD); /* Receive old format with old protocol */ final GroupChange oldGroupChangeViaOld = (GroupChange) oldProtocol.parse(oldGroupChange.wireFormat()); assertEquals( "Old message format via old protocol should use old" + " group format", oldGroup, oldGroupChangeViaOld.getGroup()); /* Receive old format with new protocol */ final GroupChange oldGroupChangeViaNew = (GroupChange) protocol.parse(oldGroupChange.wireFormat()); assertEquals( "Old message format via new protocol should use old" + " group format", oldGroup, oldGroupChangeViaNew.getGroup()); /* Receive new format with old protocol */ final GroupChange newGroupChange = protocol.new GroupChange(newGroup, NODE_NAME, GroupChangeType.ADD); try { oldProtocol.parse(newGroupChange.wireFormat()); fail("Expected InvalidMessageException when old protocol" + " receives new format message"); } catch (InvalidMessageException e) { assertEquals( "New message format via old protocol should produce" + " a version mismatch", TextProtocol.MessageError.VERSION_MISMATCH, e.getErrorType()); } }