Skip to content

Commit

Permalink
Merge pull request #4460 from rstudio/bugfix/speed-up-gwt-unittests
Browse files Browse the repository at this point in the history
Refactoring so GWT unit tests run less slowly
  • Loading branch information
gtritchie committed Mar 18, 2019
2 parents 7309488 + 31b2d66 commit bfa2350
Show file tree
Hide file tree
Showing 24 changed files with 433 additions and 198 deletions.
2 changes: 2 additions & 0 deletions src/gwt/src/org/rstudio/core/Core.gwt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<inherits name='com.google.gwt.json.JSON' />
<inherits name='com.google.gwt.http.HTTP' />

<inherits name='org.rstudio.studio.RStudio' />

<generate-with class="org.rstudio.core.rebind.command.CommandBundleGenerator" >
<when-type-assignable
class="org.rstudio.core.client.command.CommandBundle"/>
Expand Down
8 changes: 5 additions & 3 deletions src/gwt/src/org/rstudio/core/client/ConsoleOutputWriter.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ConsoleOutputWriter.java
*
* Copyright (C) 2009-17 by RStudio, Inc.
* Copyright (C) 2009-19 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
Expand Down Expand Up @@ -30,8 +30,9 @@
*/
public class ConsoleOutputWriter
{
public ConsoleOutputWriter()
public ConsoleOutputWriter(VirtualConsoleFactory vcFactory)
{
vcFactory_ = vcFactory;
output_ = new PreWidget();
}

Expand Down Expand Up @@ -86,7 +87,7 @@ public boolean outputToConsole(String text,
{
SpanElement trailing = Document.get().createSpanElement();
outEl.appendChild(trailing);
virtualConsole_ = new VirtualConsole(trailing);
virtualConsole_ = vcFactory_.create(trailing);
}

int oldLineCount = DomUtils.countLines(virtualConsole_.getParent(), true);
Expand Down Expand Up @@ -147,4 +148,5 @@ public int getCurrentLines()
private int lines_ = 0;
private final PreWidget output_;
private VirtualConsole virtualConsole_;
private VirtualConsoleFactory vcFactory_;
}
57 changes: 13 additions & 44 deletions src/gwt/src/org/rstudio/core/client/VirtualConsole.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* VirtualConsole.java
*
* Copyright (C) 2009-18 by RStudio, Inc.
* Copyright (C) 2009-19 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
Expand All @@ -23,10 +23,9 @@
import java.util.TreeMap;
import java.util.TreeSet;

import com.google.inject.assistedinject.Assisted;
import org.rstudio.core.client.regex.Match;
import org.rstudio.core.client.regex.Pattern;
import org.rstudio.studio.client.RStudioGinjector;
import org.rstudio.studio.client.workbench.prefs.model.UIPrefs;

import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.dom.client.Document;
Expand All @@ -40,9 +39,6 @@
*/
public class VirtualConsole
{
// use preference to determine ANSI color behavior
private final static int ANSI_COLOR_USE_PREF = -1;

// don't do any processing of ANSI escape codes
public final static int ANSI_COLOR_OFF = 0;

Expand All @@ -51,38 +47,20 @@ public class VirtualConsole

// strip out ANSI escape sequences but don't apply styles
public final static int ANSI_COLOR_STRIP = 2;

public VirtualConsole()
public interface Preferences
{
this(null);
int truncateLongLinesInConsoleHistory();
int consoleAnsiMode();
}

public VirtualConsole(Element parent)
{
this(parent, ANSI_COLOR_USE_PREF);
}

/**
* VirtualConsole constructor
* @param parent parent element
* @param ansiColorMode ANSI_COLOR_OFF: don't process ANSI escapes,
* ANSI_COLOR_ON: translate ANSI escapes into css styles,
* ANSI_COLOR_STRIP: strip out ANSI escape sequences but don't apply styles,
* ANSI_COLOR_USE_PREF: determine behavior from preference
*/
public VirtualConsole(Element parent, int ansiColorMode)
{
RStudioGinjector.INSTANCE.injectMembers(this);
parent_ = parent;
ansiColorMode_ = ansiColorMode;
}


@Inject
private void initialize(UIPrefs prefs)
public VirtualConsole(@Assisted Element parent, final Preferences prefs)
{
prefs_ = prefs;
parent_ = parent;
}

public void clear()
{
formfeed();
Expand Down Expand Up @@ -164,7 +142,7 @@ public String toString()
{
String output = output_.toString();

int maxLength = prefs_.truncateLongLinesInConsoleHistory().getGlobalValue();
int maxLength = prefs_.truncateLongLinesInConsoleHistory();
if (maxLength == 0)
return output;

Expand All @@ -188,13 +166,6 @@ public int getLength()
return output_.length();
}

public static String consolify(String text)
{
VirtualConsole console = new VirtualConsole();
console.submit(text);
return console.toString();
}

public Element getParent()
{
return parent_;
Expand Down Expand Up @@ -452,8 +423,7 @@ public void submit(String data, String clazz, boolean forceNewRange)

String currentClazz = clazz;

int ansiColorMode = (ansiColorMode_ == ANSI_COLOR_USE_PREF) ?
prefs_.consoleAnsiMode().getValue() : ansiColorMode_;
int ansiColorMode = prefs_.consoleAnsiMode();

// If previously determined classes from ANSI codes are available,
// combine them with input class so they are ready to use if
Expand Down Expand Up @@ -692,12 +662,11 @@ public String debugDump()
private AnsiCode ansi_;
private String partialAnsiCode_;
private AnsiCode.AnsiClazzes ansiCodeStyles_ = new AnsiCode.AnsiClazzes();
private int ansiColorMode_;

// Elements added by last submit call (only if forceNewRange was true)
private boolean captureNewElements_ = false;
private List<Element> newElements_ = new ArrayList<Element>();

// Injected ----
private UIPrefs prefs_;
private Preferences prefs_;
}
23 changes: 23 additions & 0 deletions src/gwt/src/org/rstudio/core/client/VirtualConsoleFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* VirtualConsoleFactory.java
*
* Copyright (C) 2009-19 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
package org.rstudio.core.client;

import com.google.gwt.dom.client.Element;

public interface VirtualConsoleFactory
{
// for assisted injection
VirtualConsole create(Element elem);
}
11 changes: 10 additions & 1 deletion src/gwt/src/org/rstudio/studio/client/RStudioGinModule.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* RStudioGinModule.java
*
* Copyright (C) 2009-18 by RStudio, Inc.
* Copyright (C) 2009-19 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
Expand All @@ -20,6 +20,10 @@
import com.google.inject.Singleton;
import com.google.inject.name.Names;

import org.rstudio.core.client.VirtualConsole;
import org.rstudio.core.client.VirtualConsoleFactory;
import org.rstudio.studio.client.application.events.FireEvents;
import org.rstudio.studio.client.common.console.VirtualConsolePreferences;
import org.rstudio.core.client.command.ApplicationCommandManager;
import org.rstudio.core.client.command.EditorCommandManager;
import org.rstudio.core.client.command.ShortcutViewer;
Expand Down Expand Up @@ -160,6 +164,7 @@
import org.rstudio.studio.client.workbench.views.files.model.FilesServerOperations;
import org.rstudio.studio.client.workbench.views.jobs.LauncherJobsPresenter;
import org.rstudio.studio.client.workbench.views.jobs.LauncherJobsTab;
import org.rstudio.studio.client.workbench.views.jobs.view.JobItemFactory;
import org.rstudio.studio.client.workbench.views.jobs.view.LauncherJobsPane;
import org.rstudio.studio.client.workbench.views.output.data.DataOutputTab;
import org.rstudio.studio.client.workbench.views.output.find.FindOutputPane;
Expand Down Expand Up @@ -473,6 +478,10 @@ protected void configure()
bind(RStudioAPIServerOperations.class).to(RemoteServer.class);

bind(AskSecretManager.class).in(Singleton.class);
bind(VirtualConsole.Preferences.class).to(VirtualConsolePreferences.class);
install(new GinFactoryModuleBuilder().build(VirtualConsoleFactory.class));
install(new GinFactoryModuleBuilder().build(JobItemFactory.class));
bind(FireEvents.class).to(EventBus.class);
}

private <T extends WorkbenchTab> void bindTab(String name, Class<T> clazz)
Expand Down
4 changes: 4 additions & 0 deletions src/gwt/src/org/rstudio/studio/client/RStudioGinjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.rstudio.core.client.HtmlMessageListener;
import org.rstudio.core.client.VirtualConsole;
import org.rstudio.core.client.VirtualConsoleFactory;
import org.rstudio.core.client.command.AddinCommandBinding;
import org.rstudio.core.client.command.ApplicationCommandManager;
import org.rstudio.core.client.command.EditorCommandManager;
Expand Down Expand Up @@ -112,6 +113,7 @@
import org.rstudio.studio.client.workbench.views.console.shell.assist.RCompletionManager;
import org.rstudio.studio.client.workbench.views.jobs.events.JobsPresenterEventHandlersImpl;
import org.rstudio.studio.client.workbench.views.jobs.model.JobManager;
import org.rstudio.studio.client.workbench.views.jobs.view.JobItemFactory;
import org.rstudio.studio.client.workbench.views.jobs.view.JobsDisplayImpl;
import org.rstudio.studio.client.workbench.views.output.lint.LintManager;
import org.rstudio.studio.client.workbench.views.packages.ui.CheckForUpdatesDialog;
Expand Down Expand Up @@ -320,4 +322,6 @@ public interface RStudioGinjector extends Ginjector
PlumberAPI getPlumberAPI();
JobManager getJobManager();
SessionOpener getSessionOpener();
VirtualConsoleFactory getVirtualConsoleFactory();
JobItemFactory getJobItemFactory();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* EventBus.java
*
* Copyright (C) 2009-15 by RStudio, Inc.
* Copyright (C) 2009-19 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
Expand Down Expand Up @@ -35,7 +35,7 @@
import com.google.inject.Singleton;

@Singleton
public class EventBus extends HandlerManager
public class EventBus extends HandlerManager implements FireEvents
{
@Inject
public EventBus(Provider<Satellite> pSatellite,
Expand Down Expand Up @@ -94,18 +94,21 @@ else if (crossWindow.focusMode() == CrossWindowEvent.MODE_AUXILIARY &&

}

@Override
public void fireEventToAllSatellites(CrossWindowEvent<?> event)
{
pManager_.get().dispatchCrossWindowEvent(event);
}

public void fireEventToSatellite(CrossWindowEvent<?> event,
WindowEx satelliteWindow)
@Override
public void fireEventToSatellite(CrossWindowEvent<?> event,
WindowEx satelliteWindow)
{
fireEventToSatellite(serializer_.serialize(event),
satelliteWindow);
}

@Override
public void fireEventToMainWindow(CrossWindowEvent<?> event)
{
if (Satellite.isCurrentWindowSatellite())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* FireEvents.java
*
* Copyright (C) 2009-19 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
package org.rstudio.studio.client.application.events;

import com.google.gwt.event.shared.GwtEvent;
import org.rstudio.core.client.dom.WindowEx;

public interface FireEvents
{
void fireEvent(GwtEvent<?> event);

void fireEventToAllSatellites(CrossWindowEvent<?> event);

void fireEventToSatellite(CrossWindowEvent<?> event,
WindowEx satelliteWindow);

void fireEventToMainWindow(CrossWindowEvent<?> event);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* CompileOutputBuffer.java
*
* Copyright (C) 2009-17 by RStudio, Inc.
* Copyright (C) 2009-19 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
Expand All @@ -20,6 +20,7 @@
import org.rstudio.core.client.widget.BottomScrollPanel;
import org.rstudio.core.client.widget.FontSizer;
import org.rstudio.core.client.widget.PreWidget;
import org.rstudio.studio.client.RStudioGinjector;
import org.rstudio.studio.client.workbench.views.console.ConsoleResources;

import com.google.gwt.user.client.ui.Composite;
Expand All @@ -30,7 +31,7 @@ public class CompileOutputBuffer extends Composite
public CompileOutputBuffer()
{
output_ = new PreWidget();
virtualConsole_ = new VirtualConsole(output_.getElement());
virtualConsole_ = RStudioGinjector.INSTANCE.getVirtualConsoleFactory().create(output_.getElement());
output_.setStylePrimaryName(
ConsoleResources.INSTANCE.consoleStyles().output());
FontSizer.applyNormalFontSize(output_);
Expand Down Expand Up @@ -78,7 +79,7 @@ public void scrollToBottom()
public void clear()
{
output_.setText("");
virtualConsole_ = new VirtualConsole(output_.getElement());
virtualConsole_ = RStudioGinjector.INSTANCE.getVirtualConsoleFactory().create(output_.getElement());
}

private PreWidget output_;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* CompileOutputBufferWithHighlight.java
*
* Copyright (C) 2009-12 by RStudio, Inc.
* Copyright (C) 2009-19 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
Expand Down Expand Up @@ -36,7 +36,7 @@ public CompileOutputBufferWithHighlight()
output_.setStylePrimaryName(styles_.output());
output_.addStyleName(styles_.paddedOutput());
FontSizer.applyNormalFontSize(output_);
console_ = new VirtualConsole(output_.getElement());
console_ = RStudioGinjector.INSTANCE.getVirtualConsoleFactory().create(output_.getElement());

scrollPanel_ = new BottomScrollPanel();
scrollPanel_.setSize("100%", "100%");
Expand Down

0 comments on commit bfa2350

Please sign in to comment.