@Test public void expandLink() throws Exception { EntityMessageCacheUtil.removeSessionChanges(); final ChannelMetaData ch1 = new ChannelMetaData( 0, "C1", null, ChannelMetaData.FilterType.DYNAMIC, String.class, ChannelMetaData.CacheType.NONE, false, true ); final ChannelMetaData ch2 = new ChannelMetaData( 1, "C2", 42, ChannelMetaData.FilterType.NONE, null, ChannelMetaData.CacheType.NONE, false, true ); final ChannelMetaData[] channels = new ChannelMetaData[]{ ch1, ch2 }; final ChannelAddress address1 = new ChannelAddress( ch1.getChannelId(), null ); final ChannelAddress address2a = new ChannelAddress( ch2.getChannelId(), ValueUtil.randomInt() ); final ChannelAddress address2b = new ChannelAddress( ch2.getChannelId(), ValueUtil.randomInt() ); final ChannelLink link1 = new ChannelLink( address1, address2a ); final ChannelLink link2 = new ChannelLink( address1, address2b ); final TestReplicantSessionManager sm = new TestReplicantSessionManager( channels ); final ReplicantSession session = createSession( sm ); with( session, () -> assertFalse( sm.expandLink( session, EntityMessageCacheUtil.getSessionChanges() ) ) ); assertChannelActionCount( 0 ); with( session, () -> sm.subscribe( session, address1, null ) ); assertChannelActionCount( 1 ); with( session, () -> assertFalse( sm.expandLink( session, EntityMessageCacheUtil.getSessionChanges() ) ) ); assertChannelActionCount( 1 ); final HashMap<String, Serializable> routes = new HashMap<>(); final HashMap<String, Serializable> attributes = new HashMap<>(); final HashSet<ChannelLink> links = new LinkedHashSet<>(); links.add( link1 ); links.add( link2 ); final EntityMessage message = new EntityMessage( ValueUtil.randomInt(), ValueUtil.randomInt(), 0, routes, attributes, links ); EntityMessageCacheUtil.getSessionChanges().merge( new Change( message ) ); with( session, () -> assertTrue( sm.expandLink( session, EntityMessageCacheUtil.getSessionChanges() ) ) ); assertChannelActionCount( 2 ); final SubscriptionEntry entry1 = with( session, () -> session.getSubscriptionEntry( address1 ) ); final SubscriptionEntry entry2a = with( session, () -> session.getSubscriptionEntry( address2a ) ); with( session, () -> assertNull( session.findSubscriptionEntry( address2b ) ) ); assertEquals( entry1.getInwardSubscriptions().size(), 0 ); assertEquals( entry1.getOutwardSubscriptions().size(), 1 ); assertEquals( entry2a.getInwardSubscriptions().size(), 1 ); assertEquals( entry2a.getOutwardSubscriptions().size(), 0 ); with( session, () -> assertTrue( sm.expandLink( session, EntityMessageCacheUtil.getSessionChanges() ) ) ); assertChannelActionCount( 3 ); final SubscriptionEntry entry2b = with( session, () -> session.getSubscriptionEntry( address2b ) ); assertEquals( entry1.getInwardSubscriptions().size(), 0 ); assertEquals( entry1.getOutwardSubscriptions().size(), 2 ); assertEquals( entry2a.getInwardSubscriptions().size(), 1 ); assertEquals( entry2a.getOutwardSubscriptions().size(), 0 ); assertEquals( entry2b.getInwardSubscriptions().size(), 1 ); assertEquals( entry2b.getOutwardSubscriptions().size(), 0 ); with( session, () -> assertFalse( sm.expandLink( session, EntityMessageCacheUtil.getSessionChanges() ) ) ); assertChannelActionCount( 3 ); }
boolean expandLink( @Nonnull final ReplicantSession session, @Nonnull final ChangeSet changeSet ) { for ( final Change change : changeSet.getChanges() ) { final EntityMessage entityMessage = change.getEntityMessage(); if ( entityMessage.isUpdate() ) { final Set<ChannelLink> links = entityMessage.getLinks(); if ( null != links ) { for ( final ChannelLink link : links ) { if ( expandLinkIfRequired( session, link, changeSet ) ) { return true; } } } } } return false; }
ReplicantSessionManagerImpl implements EntityMessageEndpoint, ReplicantSessionManager { boolean expandLink( @Nonnull final ReplicantSession session, @Nonnull final ChangeSet changeSet ) { for ( final Change change : changeSet.getChanges() ) { final EntityMessage entityMessage = change.getEntityMessage(); if ( entityMessage.isUpdate() ) { final Set<ChannelLink> links = entityMessage.getLinks(); if ( null != links ) { for ( final ChannelLink link : links ) { if ( expandLinkIfRequired( session, link, changeSet ) ) { return true; } } } } } return false; } }
ReplicantSessionManagerImpl implements EntityMessageEndpoint, ReplicantSessionManager { boolean expandLink( @Nonnull final ReplicantSession session, @Nonnull final ChangeSet changeSet ) { for ( final Change change : changeSet.getChanges() ) { final EntityMessage entityMessage = change.getEntityMessage(); if ( entityMessage.isUpdate() ) { final Set<ChannelLink> links = entityMessage.getLinks(); if ( null != links ) { for ( final ChannelLink link : links ) { if ( expandLinkIfRequired( session, link, changeSet ) ) { return true; } } } } } return false; }  }
ReplicantSessionManagerImpl implements EntityMessageEndpoint, ReplicantSessionManager { boolean expandLink( @Nonnull final ReplicantSession session, @Nonnull final ChangeSet changeSet ) { for ( final Change change : changeSet.getChanges() ) { final EntityMessage entityMessage = change.getEntityMessage(); if ( entityMessage.isUpdate() ) { final Set<ChannelLink> links = entityMessage.getLinks(); if ( null != links ) { for ( final ChannelLink link : links ) { if ( expandLinkIfRequired( session, link, changeSet ) ) { return true; } } } } } return false; }  @Override boolean invalidateSession( @Nonnull final ReplicantSession session ); @Override @Nullable ReplicantSession getSession( @Nonnull final String sessionId ); @Nonnull @Override Set<String> getSessionIDs(); @Override @Nonnull ReplicantSession createSession( @Nonnull final Session webSocketSession ); @SuppressWarnings( { "WeakerAccess", "unused" } ) void pingSessions(); @SuppressWarnings( "WeakerAccess" ) void removeAllSessions(); @SuppressWarnings( "WeakerAccess" ) void removeClosedSessions(); @Override boolean saveEntityMessages( @Nullable final String sessionId,
                                     @Nullable final Integer requestId,
                                     @Nonnull final Collection<EntityMessage> messages,
                                     @Nullable final ChangeSet sessionChanges ); @Override void sendChangeMessage( @Nonnull final ReplicantSession session,
                                 @Nullable final Integer requestId,
                                 @Nullable final String etag,
                                 @Nonnull final Collection<EntityMessage> messages,
                                 @Nonnull final ChangeSet changeSet ); @Override void bulkSubscribe( @Nonnull final ReplicantSession session,
                             final int channelId,
                             @Nonnull final Collection<Integer> subChannelIds,
                             @Nullable final Object filter ); @Override void subscribe( @Nonnull final ReplicantSession session,
                         @Nonnull final ChannelAddress address,
                         @Nullable final Object filter ); @Override void unsubscribe( @Nonnull final ReplicantSession session, @Nonnull final ChannelAddress address ); @Override void bulkUnsubscribe( @Nonnull final ReplicantSession session,
                               final int channelId,
                               @Nonnull final Collection<Integer> subChannelIds ); }
ReplicantSessionManagerImpl implements EntityMessageEndpoint, ReplicantSessionManager { boolean expandLink( @Nonnull final ReplicantSession session, @Nonnull final ChangeSet changeSet ) { for ( final Change change : changeSet.getChanges() ) { final EntityMessage entityMessage = change.getEntityMessage(); if ( entityMessage.isUpdate() ) { final Set<ChannelLink> links = entityMessage.getLinks(); if ( null != links ) { for ( final ChannelLink link : links ) { if ( expandLinkIfRequired( session, link, changeSet ) ) { return true; } } } } } return false; }  @Override boolean invalidateSession( @Nonnull final ReplicantSession session ); @Override @Nullable ReplicantSession getSession( @Nonnull final String sessionId ); @Nonnull @Override Set<String> getSessionIDs(); @Override @Nonnull ReplicantSession createSession( @Nonnull final Session webSocketSession ); @SuppressWarnings( { "WeakerAccess", "unused" } ) void pingSessions(); @SuppressWarnings( "WeakerAccess" ) void removeAllSessions(); @SuppressWarnings( "WeakerAccess" ) void removeClosedSessions(); @Override boolean saveEntityMessages( @Nullable final String sessionId,
                                     @Nullable final Integer requestId,
                                     @Nonnull final Collection<EntityMessage> messages,
                                     @Nullable final ChangeSet sessionChanges ); @Override void sendChangeMessage( @Nonnull final ReplicantSession session,
                                 @Nullable final Integer requestId,
                                 @Nullable final String etag,
                                 @Nonnull final Collection<EntityMessage> messages,
                                 @Nonnull final ChangeSet changeSet ); @Override void bulkSubscribe( @Nonnull final ReplicantSession session,
                             final int channelId,
                             @Nonnull final Collection<Integer> subChannelIds,
                             @Nullable final Object filter ); @Override void subscribe( @Nonnull final ReplicantSession session,
                         @Nonnull final ChannelAddress address,
                         @Nullable final Object filter ); @Override void unsubscribe( @Nonnull final ReplicantSession session, @Nonnull final ChannelAddress address ); @Override void bulkUnsubscribe( @Nonnull final ReplicantSession session,
                               final int channelId,
                               @Nonnull final Collection<Integer> subChannelIds );  }