@Test
  public void testGatewayQueueWithOverflowNoPersistence() throws Exception {
    String gatewayHubName = "testGatewayQueueWithOverflowNoPersistence";

    GatewayProxy.GatewayQueue gatewayQueue = new GatewayProxy.GatewayQueue();

    gatewayQueue.setAlertThreshold(100);
    gatewayQueue.setBatchSize(250);
    gatewayQueue.setBatchTimeInterval(120000);
    gatewayQueue.setDiskStoreRef("diskZ");
    gatewayQueue.setEnableBatchConflation(true);
    gatewayQueue.setMaximumQueueMemory(2048);
    gatewayQueue.setPersistent(false);

    GatewayProxy gatewayProxy = new GatewayProxy();

    gatewayProxy.setId("gatewayProxyId");
    gatewayProxy.setConcurrencyLevel(2);
    gatewayProxy.setEndpoints(null);
    gatewayProxy.setListeners(null);
    gatewayProxy.setOrderPolicy(Gateway.OrderPolicy.THREAD);
    gatewayProxy.setQueue(gatewayQueue);
    gatewayProxy.setSocketBufferSize(4096);
    gatewayProxy.setSocketReadTimeout(60);

    GatewayHub mockGatewayHub =
        mock(GatewayHub.class, "testGatewayQueueWithOverflowNoPersistence.MockGatewayHub");

    Gateway mockGateway =
        mock(Gateway.class, "testGatewayQueueWithOverflowNoPersistence.MockGateway");

    GatewayQueueAttributes mockGatewayQueueAttributes =
        mock(
            GatewayQueueAttributes.class,
            "testGatewayQueueWithOverflowNoPersistence.MockGatewayQueueAttributes");

    when(mockCache.addGatewayHub(eq(gatewayHubName), eq(10224))).thenReturn(mockGatewayHub);
    when(mockCache.getGatewayHub(eq(gatewayHubName))).thenReturn(mockGatewayHub);
    when(mockGatewayHub.addGateway(
            eq(gatewayProxy.getId()), eq(gatewayProxy.getConcurrencyLevel())))
        .thenReturn(mockGateway);
    when(mockGatewayHub.getManualStart()).thenReturn(GatewayHub.DEFAULT_MANUAL_START);
    when(mockGateway.getQueueAttributes()).thenReturn(mockGatewayQueueAttributes);

    factoryBean.setGateways(Arrays.asList(gatewayProxy));
    factoryBean.setName(gatewayHubName);
    factoryBean.setPort(10224);
    factoryBean.afterPropertiesSet();

    verify(mockGatewayHub, times(1)).setBindAddress(eq(GatewayHub.DEFAULT_BIND_ADDRESS));
    verify(mockGatewayHub, times(1)).setManualStart(eq(GatewayHub.DEFAULT_MANUAL_START));
    verify(mockGatewayHub, times(1)).setMaxConnections(GatewayHub.DEFAULT_MAX_CONNECTIONS);
    verify(mockGatewayHub, times(1))
        .setMaximumTimeBetweenPings(eq(GatewayHub.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS));
    verify(mockGatewayHub, times(1)).setSocketBufferSize(eq(GatewayHub.DEFAULT_SOCKET_BUFFER_SIZE));
    verify(mockGatewayHub, times(1)).setStartupPolicy(eq(GatewayHub.DEFAULT_STARTUP_POLICY));
    verify(mockGatewayHub, times(1)).start();
    verify(mockGatewayHub, times(1))
        .addGateway(eq(gatewayProxy.getId()), eq(gatewayProxy.getConcurrencyLevel()));
    verify(mockGateway, times(1)).setOrderPolicy(eq(gatewayProxy.getOrderPolicy()));
    verify(mockGateway, times(1)).setSocketBufferSize(eq(gatewayProxy.getSocketBufferSize()));
    verify(mockGateway, times(1)).setSocketReadTimeout(eq(gatewayProxy.getSocketReadTimeout()));
    verify(mockGatewayQueueAttributes, times(1))
        .setAlertThreshold(gatewayQueue.getAlertThreshold());
    verify(mockGatewayQueueAttributes, times(1))
        .setBatchConflation(gatewayQueue.getEnableBatchConflation());
    verify(mockGatewayQueueAttributes, times(1)).setBatchSize(gatewayQueue.getBatchSize());
    verify(mockGatewayQueueAttributes, times(1))
        .setBatchTimeInterval(gatewayQueue.getBatchTimeInterval());
    verify(mockGatewayQueueAttributes, times(1)).setDiskStoreName(gatewayQueue.getDiskStoreRef());
    verify(mockGatewayQueueAttributes, times(1))
        .setMaximumQueueMemory(gatewayQueue.getMaximumQueueMemory());
    verify(mockGatewayQueueAttributes, times(1)).setEnablePersistence(gatewayQueue.getPersistent());
  }
コード例 #2
0
  /**
   * Creates the server cache, and configure wan
   *
   * @param site - used to configure gateway endpoint
   * @param name - used to generate name
   * @param ePort1 - GatewayHub port
   * @param ePort2 - other GatewayHub port
   * @throws Exception - thrown if any problem occurs in setting up the server
   */
  public static Object createServerCache(
      String myHubId,
      String hubImSendingTo,
      Integer listenOnPort,
      Integer sendToPort,
      String host,
      int mcast_port,
      boolean enableStorage,
      boolean enableGateway)
      throws Exception {
    Properties props = new Properties();

    props.setProperty(DistributionConfig.MCAST_PORT_NAME, mcast_port + "");
    props.setProperty(DistributionConfig.LOCATORS_NAME, "");
    cache = impl.createCache(props);
    AttributesFactory factory = impl.getServerCacheAttributesFactory(enableStorage);
    factory.setEnableGateway(true);
    factory.setCloningEnabled(false);
    factory.setCacheListener(
        new CacheListener() {

          public void afterCreate(EntryEvent event) {
            // TODO Auto-generated method stub
          }

          public void afterDestroy(EntryEvent event) {
            // TODO Auto-generated method stub

          }

          public void afterInvalidate(EntryEvent event) {
            // TODO Auto-generated method stub

          }

          public void afterRegionClear(RegionEvent event) {
            // TODO Auto-generated method stub

          }

          public void afterRegionCreate(RegionEvent event) {
            // TODO Auto-generated method stub

          }

          public void afterRegionDestroy(RegionEvent event) {
            // TODO Auto-generated method stub

          }

          public void afterRegionInvalidate(RegionEvent event) {
            // TODO Auto-generated method stub

          }

          public void afterRegionLive(RegionEvent event) {
            // TODO Auto-generated method stub

          }

          public void afterUpdate(EntryEvent event) {
            // TODO Auto-generated method stub

          }

          public void close() {
            // TODO Auto-generated method stub

          }
        });

    RegionAttributes attrs = factory.create();

    cache.createRegion(REGION_NAME, attrs);

    if (enableGateway) {
      GatewayHub hub1 = cache.addGatewayHub(myHubId, listenOnPort.intValue());
      Gateway gateway1 = hub1.addGateway(hubImSendingTo);
      gateway1.addEndpoint("dont matter", host, sendToPort.intValue());

      GatewayQueueAttributes queueAttributes = gateway1.getQueueAttributes();
      queueAttributes.setMaximumQueueMemory(1);
      queueAttributes.setBatchSize(1);
      setDiskStoreForGateway(cache, gateway1.getId(), queueAttributes);
      hub1.start();
      gateway1.start();
    }
    return new Integer(0);
  }
  @Test
  public void testDoInit() throws Exception {
    String gatewayHubName = "testDoInit";

    GatewayProxy.GatewayEndpoint gatewayEndpointOne = new GatewayProxy.GatewayEndpoint();

    gatewayEndpointOne.setHost("localhost");
    gatewayEndpointOne.setId("123");
    gatewayEndpointOne.setPort(2121);

    GatewayProxy.GatewayEndpoint gatewayEndpointTwo = new GatewayProxy.GatewayEndpoint();

    gatewayEndpointOne.setHost("localhost");
    gatewayEndpointOne.setId("456");
    gatewayEndpointOne.setPort(4242);

    GatewayEventListener mockGatewayListener =
        mock(GatewayEventListener.class, "testDoInit.MockGatewayEventListener");

    GatewayProxy.GatewayQueue gatewayQueue = new GatewayProxy.GatewayQueue();

    gatewayQueue.setAlertThreshold(20);
    gatewayQueue.setBatchSize(100);
    gatewayQueue.setBatchTimeInterval(60000);
    gatewayQueue.setDiskStoreRef("diskX");
    gatewayQueue.setEnableBatchConflation(true);
    gatewayQueue.setMaximumQueueMemory(1024);
    gatewayQueue.setPersistent(true);

    GatewayProxy gatewayProxy = new GatewayProxy();

    gatewayProxy.setId("gatewayProxyId");
    gatewayProxy.setConcurrencyLevel(4);
    gatewayProxy.setEndpoints(Arrays.asList(gatewayEndpointOne, gatewayEndpointTwo));
    gatewayProxy.setListeners(Arrays.asList(mockGatewayListener));
    gatewayProxy.setOrderPolicy(Gateway.OrderPolicy.THREAD);
    gatewayProxy.setQueue(gatewayQueue);
    gatewayProxy.setSocketBufferSize(16384);
    gatewayProxy.setSocketReadTimeout(300);

    GatewayHub mockGatewayHub = mock(GatewayHub.class, "testDoInit.MockGatewayHub");

    Gateway mockGateway = mock(Gateway.class, "testDoInit.MockGateway");

    GatewayQueueAttributes mockGatewayQueueAttributes =
        mock(GatewayQueueAttributes.class, "testDoInit.MockGatewayQueueAttributes");

    when(mockCache.addGatewayHub(eq(gatewayHubName), eq(8484))).thenReturn(mockGatewayHub);
    when(mockCache.getGatewayHub(eq(gatewayHubName))).thenReturn(mockGatewayHub);
    when(mockGatewayHub.addGateway(
            eq(gatewayProxy.getId()), eq(gatewayProxy.getConcurrencyLevel().intValue())))
        .thenReturn(mockGateway);
    when(mockGatewayHub.getManualStart()).thenReturn(false);
    when(mockGateway.getQueueAttributes()).thenReturn(mockGatewayQueueAttributes);

    factoryBean.setBindAddress("10.124.210.42");
    factoryBean.setGateways(Arrays.asList(gatewayProxy));
    factoryBean.setManualStart(false);
    factoryBean.setMaxConnections(50);
    factoryBean.setMaximumTimeBetweenPings(20480);
    factoryBean.setName(gatewayHubName);
    factoryBean.setPort(8484);
    factoryBean.setSocketBufferSize(4096);
    factoryBean.setStartupPolicy(StartupPolicyType.PRIMARY);
    factoryBean.afterPropertiesSet();

    verify(mockGatewayHub, times(1)).setBindAddress(eq("10.124.210.42"));
    verify(mockGatewayHub, times(1)).setManualStart(eq(false));
    verify(mockGatewayHub, times(1)).setMaxConnections(eq(50));
    verify(mockGatewayHub, times(1)).setMaximumTimeBetweenPings(eq(20480));
    verify(mockGatewayHub, times(1)).setSocketBufferSize(eq(4096));
    verify(mockGatewayHub, times(1)).setStartupPolicy(eq(StartupPolicyType.PRIMARY.getName()));
    verify(mockGatewayHub, times(1))
        .addGateway(eq(gatewayProxy.getId()), eq(gatewayProxy.getConcurrencyLevel()));
    verify(mockGatewayHub, times(1)).start();
    verify(mockGateway, times(1))
        .addEndpoint(
            eq(gatewayEndpointOne.getId()),
            eq(gatewayEndpointOne.getHost()),
            eq(gatewayEndpointOne.getPort()));
    verify(mockGateway, times(1))
        .addEndpoint(
            eq(gatewayEndpointTwo.getId()),
            eq(gatewayEndpointTwo.getHost()),
            eq(gatewayEndpointTwo.getPort()));
    verify(mockGateway, times(1)).addListener(same(mockGatewayListener));
    verify(mockGateway, times(1)).setOrderPolicy(eq(gatewayProxy.getOrderPolicy()));
    verify(mockGateway, times(1)).setSocketBufferSize(eq(gatewayProxy.getSocketBufferSize()));
    verify(mockGateway, times(1)).setSocketReadTimeout(eq(gatewayProxy.getSocketReadTimeout()));
    verify(mockGateway, times(1)).getQueueAttributes();
    verify(mockGatewayQueueAttributes, times(1))
        .setAlertThreshold(eq(gatewayQueue.getAlertThreshold()));
    verify(mockGatewayQueueAttributes, times(1))
        .setBatchConflation(eq(gatewayQueue.getEnableBatchConflation()));
    verify(mockGatewayQueueAttributes, times(1)).setBatchSize(eq(gatewayQueue.getBatchSize()));
    verify(mockGatewayQueueAttributes, times(1))
        .setBatchTimeInterval(eq(gatewayQueue.getBatchTimeInterval()));
    verify(mockGatewayQueueAttributes, times(1))
        .setDiskStoreName(eq(gatewayQueue.getDiskStoreRef()));
    verify(mockGatewayQueueAttributes, times(1))
        .setMaximumQueueMemory(eq(gatewayQueue.getMaximumQueueMemory()));
    verify(mockGatewayQueueAttributes, times(1))
        .setEnablePersistence(eq(gatewayQueue.getPersistent()));
  }