Skip to content

Commit

Permalink
also fix priortizer
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeis committed Oct 1, 2016
1 parent 1e19b3b commit f83d4f2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.openqa.grid.internal.listeners.Prioritizer;
import org.openqa.grid.internal.utils.CapabilityMatcher;
import org.openqa.grid.internal.utils.DefaultCapabilityMatcher;
import org.openqa.grid.internal.utils.configuration.converters.CapabilityMatcherStringConverter;
import org.openqa.grid.internal.utils.configuration.converters.StringToClassConverter;
import org.openqa.grid.internal.utils.configuration.validators.FileExistsValueValidator;

import java.io.IOException;
Expand Down Expand Up @@ -60,7 +60,7 @@ public class GridHubConfiguration extends GridConfiguration {
@Parameter(
names = { "-matcher", "-capabilityMatcher" },
description = "<String> class name : a class implementing the CapabilityMatcher interface. Specifies the logic the hub will follow to define whether a request can be assigned to a node. For example, if you want to have the matching process use regular expressions instead of exact match when specifying browser version. ALL nodes of a grid ecosystem would then use the same capabilityMatcher, as defined here. Default is org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
converter = CapabilityMatcherStringConverter.class
converter = StringToClassConverter.CapabilityMatcherStringConverter.class
)
public CapabilityMatcher capabilityMatcher = new DefaultCapabilityMatcher();

Expand All @@ -75,7 +75,7 @@ public class GridHubConfiguration extends GridConfiguration {
@Parameter(
names = "-prioritizer",
description = "<String> class name : a class implementing the Prioritizer interface. Specify a custom Prioritizer if you want to sort the order in which new session requests are processed when there is a queue. Default to null ( no priority = FIFO )",
converter = PrioritizerString.class
converter = StringToClassConverter.PrioritizerStringConverter.class
)
public Prioritizer prioritizer = null;

Expand Down Expand Up @@ -119,18 +119,6 @@ public static GridHubConfiguration loadFromJSON(JsonObject json) {
}
}

private class PrioritizerString implements IStringConverter<Prioritizer> {
@Override
public Prioritizer convert(String prioritizerClass) {
try {
return (Prioritizer) Class.forName(prioritizerClass).newInstance();
} catch (Throwable e) {
throw new GridConfigurationException("Error creating Prioritizer from class " +
prioritizerClass + " : " + e.getMessage(), e);
}
}
}

public void merge(GridNodeConfiguration other) {
super.merge(other);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@
import com.beust.jcommander.IStringConverter;

import org.openqa.grid.common.exception.GridConfigurationException;
import org.openqa.grid.internal.listeners.Prioritizer;
import org.openqa.grid.internal.utils.CapabilityMatcher;

public class CapabilityMatcherStringConverter implements IStringConverter<CapabilityMatcher> {
@Override
public CapabilityMatcher convert(String capabilityMatcherClass) {
public abstract class StringToClassConverter<E> {
public E convert(String capabilityMatcherClass) {
try {
return (CapabilityMatcher) Class.forName(capabilityMatcherClass).newInstance();
return (E) Class.forName(capabilityMatcherClass).newInstance();
} catch (Throwable e) {
throw new GridConfigurationException("Error creating Prioritizer from class " +
throw new GridConfigurationException("Error creating class with " +
capabilityMatcherClass + " : " + e.getMessage(), e);
}
}

public static class CapabilityMatcherStringConverter extends StringToClassConverter<CapabilityMatcher> implements IStringConverter<CapabilityMatcher>{}

public static class PrioritizerStringConverter extends StringToClassConverter<Prioritizer> implements IStringConverter<Prioritizer>{}

}
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ public void testToString() {

@Test
public void testJcommanderConverterCapabilityMatcher() {
String[] hubArgs = {"-role", "hub", "-capabilityMatcher", "org.openqa.grid.internal.utils.DefaultCapabilityMatcher"};
String[] hubArgs = {"-capabilityMatcher", "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
"-prioritizer", "org.openqa.grid.internal.utils.configuration.PlaceHolderTestingPrioritizer"};
GridHubConfiguration ghc = new GridHubConfiguration();
new JCommander(ghc, hubArgs);
assertEquals("org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
ghc.capabilityMatcher.getClass().getCanonicalName());
assertEquals("org.openqa.grid.internal.utils.configuration.PlaceHolderTestingPrioritizer",
ghc.prioritizer.getClass().getCanonicalName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.grid.internal.utils.configuration;

import org.openqa.grid.internal.listeners.Prioritizer;

import java.util.Map;

public class PlaceHolderTestingPrioritizer implements Prioritizer {
@Override
public int compareTo(Map<String, Object> a, Map<String, Object> b) {
return 0;
}
}

0 comments on commit f83d4f2

Please sign in to comment.