AsyncLaneSwitcher { public static void switchLane(NodeBuilder idxBuilder, String laneName) { PropertyState currentAsyncState = idxBuilder.getProperty(ASYNC_PROPERTY_NAME); PropertyState newAsyncState = PropertyStates.createProperty(ASYNC_PROPERTY_NAME, laneName, Type.STRING); if (idxBuilder.hasProperty(ASYNC_PREVIOUS)){ return; } PropertyState previousAsyncState; if (currentAsyncState == null) { previousAsyncState = PropertyStates.createProperty(ASYNC_PREVIOUS, ASYNC_PREVIOUS_NONE); } else { previousAsyncState = clone(ASYNC_PREVIOUS, currentAsyncState); } idxBuilder.setProperty(previousAsyncState); idxBuilder.setProperty(newAsyncState); }  static void switchLane(NodeBuilder idxBuilder, String laneName); static String getTempLaneName(String laneName); static void revertSwitch(NodeBuilder idxBuilder, String indexPath); static boolean isNone(PropertyState previousAsync);  }
@Test public void switchNone() throws Exception{ AsyncLaneSwitcher.switchLane(builder, "foo"); PropertyState previous = builder.getProperty(AsyncLaneSwitcher.ASYNC_PREVIOUS); assertNotNull(previous); assertEquals(AsyncLaneSwitcher.ASYNC_PREVIOUS_NONE, previous.getValue(Type.STRING)); }
@Test public void switchSingleAsync() throws Exception{ builder.setProperty(ASYNC_PROPERTY_NAME, "async"); AsyncLaneSwitcher.switchLane(builder, "foo"); PropertyState previous = builder.getProperty(AsyncLaneSwitcher.ASYNC_PREVIOUS); assertNotNull(previous); assertEquals("async", previous.getValue(Type.STRING)); }
@Test public void switchAsyncArray() throws Exception{ builder.setProperty(ASYNC_PROPERTY_NAME, asList("async", "nrt"), Type.STRINGS); AsyncLaneSwitcher.switchLane(builder, "foo"); PropertyState previous = builder.getProperty(AsyncLaneSwitcher.ASYNC_PREVIOUS); assertNotNull(previous); assertEquals(asList("async", "nrt"), previous.getValue(Type.STRINGS)); }
@Test public void multipleSwitch() throws Exception{ builder.setProperty(ASYNC_PROPERTY_NAME, "async"); AsyncLaneSwitcher.switchLane(builder, "foo"); AsyncLaneSwitcher.switchLane(builder, "foo"); PropertyState previous = builder.getProperty(AsyncLaneSwitcher.ASYNC_PREVIOUS); assertNotNull(previous); assertEquals("async", previous.getValue(Type.STRING)); }