use of java.lang.Void in project hadoop by apache.
the class TestFetcher method testInterruptInMemory.
@Test(timeout = 10000)
public void testInterruptInMemory() throws Exception {
final int FETCHER = 2;
IFileWrappedMapOutput<Text, Text> immo = spy(new InMemoryMapOutput<Text, Text>(job, id, mm, 100, null, true));
when(mm.reserve(any(TaskAttemptID.class), anyLong(), anyInt())).thenReturn(immo);
doNothing().when(mm).waitForResource();
when(ss.getHost()).thenReturn(host);
String replyHash = SecureShuffleUtils.generateHash(encHash.getBytes(), key);
when(connection.getResponseCode()).thenReturn(200);
when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_NAME)).thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_NAME);
when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_VERSION)).thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION);
when(connection.getHeaderField(SecureShuffleUtils.HTTP_HEADER_REPLY_URL_HASH)).thenReturn(replyHash);
ShuffleHeader header = new ShuffleHeader(map1ID.toString(), 10, 10, 1);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
header.write(new DataOutputStream(bout));
final StuckInputStream in = new StuckInputStream(new ByteArrayInputStream(bout.toByteArray()));
when(connection.getInputStream()).thenReturn(in);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock ignore) throws IOException {
in.close();
return null;
}
}).when(connection).disconnect();
Fetcher<Text, Text> underTest = new FakeFetcher<Text, Text>(job, id, ss, mm, r, metrics, except, key, connection, FETCHER);
underTest.start();
// wait for read in inputstream
in.waitForFetcher();
underTest.shutDown();
// rely on test timeout to kill if stuck
underTest.join();
assertTrue(in.wasClosedProperly());
verify(immo).abort();
}
use of java.lang.Void in project hadoop by apache.
the class TestFetcher method testCopyFromHostWithRetry.
@SuppressWarnings("unchecked")
@Test(timeout = 10000)
public void testCopyFromHostWithRetry() throws Exception {
InMemoryMapOutput<Text, Text> immo = mock(InMemoryMapOutput.class);
ss = mock(ShuffleSchedulerImpl.class);
Fetcher<Text, Text> underTest = new FakeFetcher<Text, Text>(jobWithRetry, id, ss, mm, r, metrics, except, key, connection, true);
String replyHash = SecureShuffleUtils.generateHash(encHash.getBytes(), key);
when(connection.getResponseCode()).thenReturn(200);
when(connection.getHeaderField(SecureShuffleUtils.HTTP_HEADER_REPLY_URL_HASH)).thenReturn(replyHash);
ShuffleHeader header = new ShuffleHeader(map1ID.toString(), 10, 10, 1);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
header.write(new DataOutputStream(bout));
ByteArrayInputStream in = new ByteArrayInputStream(bout.toByteArray());
when(connection.getInputStream()).thenReturn(in);
when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_NAME)).thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_NAME);
when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_VERSION)).thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION);
when(mm.reserve(any(TaskAttemptID.class), anyLong(), anyInt())).thenReturn(immo);
final long retryTime = Time.monotonicNow();
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock ignore) throws IOException {
// Emulate host down for 3 seconds.
if ((Time.monotonicNow() - retryTime) <= 3000) {
throw new java.lang.InternalError();
}
return null;
}
}).when(immo).shuffle(any(MapHost.class), any(InputStream.class), anyLong(), anyLong(), any(ShuffleClientMetrics.class), any(Reporter.class));
underTest.copyFromHost(host);
verify(ss, never()).copyFailed(any(TaskAttemptID.class), any(MapHost.class), anyBoolean(), anyBoolean());
}
use of java.lang.Void in project hadoop by apache.
the class TestFetcher method testInterruptOnDisk.
@Test(timeout = 10000)
public void testInterruptOnDisk() throws Exception {
final int FETCHER = 7;
Path p = new Path("file:///tmp/foo");
Path pTmp = OnDiskMapOutput.getTempPath(p, FETCHER);
FileSystem mFs = mock(FileSystem.class, RETURNS_DEEP_STUBS);
IFileWrappedMapOutput<Text, Text> odmo = spy(new OnDiskMapOutput<Text, Text>(map1ID, mm, 100L, job, FETCHER, true, mFs, p));
when(mm.reserve(any(TaskAttemptID.class), anyLong(), anyInt())).thenReturn(odmo);
doNothing().when(mm).waitForResource();
when(ss.getHost()).thenReturn(host);
String replyHash = SecureShuffleUtils.generateHash(encHash.getBytes(), key);
when(connection.getResponseCode()).thenReturn(200);
when(connection.getHeaderField(SecureShuffleUtils.HTTP_HEADER_REPLY_URL_HASH)).thenReturn(replyHash);
ShuffleHeader header = new ShuffleHeader(map1ID.toString(), 10, 10, 1);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
header.write(new DataOutputStream(bout));
final StuckInputStream in = new StuckInputStream(new ByteArrayInputStream(bout.toByteArray()));
when(connection.getInputStream()).thenReturn(in);
when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_NAME)).thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_NAME);
when(connection.getHeaderField(ShuffleHeader.HTTP_HEADER_VERSION)).thenReturn(ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock ignore) throws IOException {
in.close();
return null;
}
}).when(connection).disconnect();
Fetcher<Text, Text> underTest = new FakeFetcher<Text, Text>(job, id, ss, mm, r, metrics, except, key, connection, FETCHER);
underTest.start();
// wait for read in inputstream
in.waitForFetcher();
underTest.shutDown();
// rely on test timeout to kill if stuck
underTest.join();
assertTrue(in.wasClosedProperly());
verify(mFs).create(eq(pTmp));
verify(mFs).delete(eq(pTmp), eq(false));
verify(odmo).abort();
}
use of java.lang.Void in project WorldPainter by Captain-Chaos.
the class App method open.
public void open(final File file) {
logger.info("Loading world " + file.getAbsolutePath());
// Free up memory of the world and the undo buffer
setWorld(null);
final World2 newWorld = ProgressDialog.executeTask(this, new ProgressTask<World2>() {
@Override
public String getName() {
return strings.getString("loading.world");
}
@Override
public World2 execute(ProgressReceiver progressReceiver) throws OperationCancelled {
try {
WorldIO worldIO = new WorldIO();
worldIO.load(new FileInputStream(file));
World2 world = worldIO.getWorld();
world.addHistoryEntry(HistoryEntry.WORLD_LOADED, file);
if (logger.isDebugEnabled() && (world.getMetadata() != null)) {
logMetadataAsDebug(world.getMetadata());
}
return world;
} catch (UnloadableWorldException e) {
logger.error("Could not load world from file " + file, e);
if (e.getMetadata() != null) {
logMetadataAsError(e.getMetadata());
}
reportUnloadableWorldException(e);
return null;
} catch (IOException e) {
throw new RuntimeException("I/O error while loading world", e);
}
}
private void appendMetadata(StringBuilder sb, Map<String, Object> metadata) {
for (Map.Entry<String, Object> entry : metadata.entrySet()) {
switch(entry.getKey()) {
case World2.METADATA_KEY_WP_VERSION:
sb.append("Saved with WorldPainter ").append(entry.getValue());
String build = (String) metadata.get(World2.METADATA_KEY_WP_BUILD);
if (build != null) {
sb.append(" (").append(build).append(')');
}
sb.append('\n');
break;
case World2.METADATA_KEY_TIMESTAMP:
sb.append("Saved on ").append(SimpleDateFormat.getDateTimeInstance().format((Date) entry.getValue())).append('\n');
break;
case World2.METADATA_KEY_PLUGINS:
String[][] plugins = (String[][]) entry.getValue();
for (String[] plugin : plugins) {
sb.append("Plugin: ").append(plugin[0]).append(" (").append(plugin[1]).append(")\n");
}
break;
}
}
}
private void logMetadataAsDebug(Map<String, Object> metadata) {
StringBuilder sb = new StringBuilder("Metadata from world file:\n");
appendMetadata(sb, metadata);
logger.debug(sb.toString());
}
private void logMetadataAsError(Map<String, Object> metadata) {
StringBuilder sb = new StringBuilder("Metadata from world file:\n");
appendMetadata(sb, metadata);
logger.error(sb.toString());
}
private void reportUnloadableWorldException(UnloadableWorldException e) {
try {
String text;
if (e.getMetadata() != null) {
StringBuilder sb = new StringBuilder("WorldPainter could not load the file. The cause may be one of:\n" + "\n" + "* The file is damaged or corrupted\n" + "* The file was created with a newer version of WorldPainter\n" + "* The file was created using WorldPainter plugins which you do not have\n" + "\n");
appendMetadata(sb, e.getMetadata());
text = sb.toString();
} else {
text = "WorldPainter could not load the file. The cause may be one of:\n" + "\n" + "* The file is not a WorldPainter world\n" + "* The file is damaged or corrupted\n" + "* The file was created with a newer version of WorldPainter\n" + "* The file was created using WorldPainter plugins which you do not have";
}
SwingUtilities.invokeAndWait(() -> showMessageDialog(App.this, text, strings.getString("file.damaged"), ERROR_MESSAGE));
} catch (InterruptedException e2) {
throw new RuntimeException("Thread interrupted while reporting unloadable file " + file, e2);
} catch (InvocationTargetException e2) {
throw new RuntimeException("Invocation target exception while reporting unloadable file " + file, e2);
}
}
}, false);
if (newWorld == null) {
// The file was damaged
return;
}
if (!isBackupFile(file)) {
lastSelectedFile = file;
} else {
lastSelectedFile = null;
}
// Log an event
Configuration config = Configuration.getInstance();
EventVO event = new EventVO(EVENT_KEY_ACTION_OPEN_WORLD).addTimestamp();
event.setAttribute(ATTRIBUTE_KEY_MAX_HEIGHT, newWorld.getMaxHeight());
Dimension loadedDimension = newWorld.getDimension(0);
event.setAttribute(ATTRIBUTE_KEY_TILES, loadedDimension.getTiles().size());
logLayers(loadedDimension, event, "");
loadedDimension = newWorld.getDimension(1);
if (loadedDimension != null) {
event.setAttribute(ATTRIBUTE_KEY_NETHER_TILES, loadedDimension.getTiles().size());
logLayers(loadedDimension, event, "nether.");
}
loadedDimension = newWorld.getDimension(2);
if (loadedDimension != null) {
event.setAttribute(ATTRIBUTE_KEY_END_TILES, loadedDimension.getTiles().size());
logLayers(loadedDimension, event, "end.");
}
if (newWorld.getImportedFrom() != null) {
event.setAttribute(ATTRIBUTE_KEY_IMPORTED_WORLD, true);
}
config.logEvent(event);
Set<World2.Warning> warnings = newWorld.getWarnings();
if ((warnings != null) && (!warnings.isEmpty())) {
for (World2.Warning warning : warnings) {
switch(warning) {
case AUTO_BIOMES_DISABLED:
if (showOptionDialog(this, "Automatic Biomes were previously enabled for this world but have been disabled.\nPress More Info for more information, including how to reenable it.", "Automatic Biomes Disabled", DEFAULT_OPTION, WARNING_MESSAGE, null, new Object[] { "More Info", "OK" }, "OK") == 0) {
try {
DesktopUtils.open(new URL("https://www.worldpainter.net/doc/legacy/newautomaticbiomes"));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
break;
case AUTO_BIOMES_ENABLED:
if (showOptionDialog(this, "Automatic Biomes were previously disabled for this world but have been enabled.\nPress More Info for more information, including how to disable it.", "Automatic Biomes Enabled", DEFAULT_OPTION, WARNING_MESSAGE, null, new Object[] { "More Info", "OK" }, "OK") == 0) {
try {
DesktopUtils.open(new URL("https://www.worldpainter.net/doc/legacy/newautomaticbiomes"));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
break;
}
}
}
if (newWorld.isAskToConvertToAnvil() && (newWorld.getMaxHeight() == DEFAULT_MAX_HEIGHT_1) && (newWorld.getImportedFrom() == null)) {
if (showConfirmDialog(this, strings.getString("this.world.is.128.blocks.high"), strings.getString("convert.world.height"), YES_NO_OPTION) == YES_OPTION) {
ChangeHeightDialog.resizeWorld(newWorld, HeightTransform.IDENTITY, DEFAULT_MAX_HEIGHT_2, this);
newWorld.addHistoryEntry(HistoryEntry.WORLD_MAX_HEIGHT_CHANGED, DEFAULT_MAX_HEIGHT_2);
// with the old format
if (newWorld.getPlatform() != null) {
newWorld.setPlatform(DefaultPlugin.JAVA_ANVIL);
}
// Log event
config.logEvent(new EventVO(EVENT_KEY_ACTION_MIGRATE_HEIGHT).addTimestamp());
}
// Don't ask again, no matter what the user answered
newWorld.setAskToConvertToAnvil(false);
}
if (newWorld.isAskToRotate() && (newWorld.getUpIs() == Direction.WEST) && (newWorld.getImportedFrom() == null)) {
if (showConfirmDialog(this, strings.getString("this.world.was.created.when.north.was.to.the.right"), strings.getString("rotate.world"), YES_NO_OPTION) == YES_OPTION) {
ProgressDialog.executeTask(this, new ProgressTask<java.lang.Void>() {
@Override
public String getName() {
return strings.getString("rotating.world");
}
@Override
public java.lang.Void execute(ProgressReceiver progressReceiver) throws OperationCancelled {
newWorld.transform(CoordinateTransform.ROTATE_CLOCKWISE_270_DEGREES, progressReceiver);
for (Dimension dimension : newWorld.getDimensions()) {
newWorld.addHistoryEntry(HistoryEntry.WORLD_DIMENSION_ROTATED, dimension.getName(), 270);
}
return null;
}
}, false);
// Log event
config.logEvent(new EventVO(EVENT_KEY_ACTION_MIGRATE_ROTATION).addTimestamp());
}
// Don't ask again, no matter what the user answered
newWorld.setAskToRotate(false);
}
// Make sure the world name is always the same as the file name, to
// avoid confusion, unless the only difference is illegal filename
// characters changed into underscores. Do this here as well as when
// saving, because the file might have been renamed
String name = isBackupFile(file) ? getOriginalFile(file).getName() : file.getName();
int p = name.lastIndexOf('.');
if (p != -1) {
name = name.substring(0, p);
}
String worldName = newWorld.getName();
if (worldName.length() != name.length()) {
newWorld.setName(name);
} else {
for (int i = 0; i < name.length(); i++) {
if ((name.charAt(i) != '_') && (name.charAt(i) != worldName.charAt(i))) {
newWorld.setName(name);
break;
}
}
}
newWorld.setDirty(false);
setWorld(newWorld);
addRecentlyUsedWorld(file);
if (newWorld.getImportedFrom() != null) {
enableImportedWorldOperation();
} else {
disableImportedWorldOperation();
}
}
use of java.lang.Void in project WorldPainter by Captain-Chaos.
the class App method createCustomLayerButton.
// PaletteManager.ButtonProvider
@Override
public List<Component> createCustomLayerButton(final CustomLayer layer) {
final List<Component> buttonComponents = createLayerButton(layer, '\0');
final JToggleButton button = (JToggleButton) buttonComponents.get(2);
button.setToolTipText(button.getToolTipText() + "; right-click for options");
button.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
showPopup(e);
}
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.isPopupTrigger()) {
showPopup(e);
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
showPopup(e);
}
}
private void showPopup(MouseEvent e) {
JPopupMenu popup = new JPopupMenu();
JMenuItem menuItem = new JMenuItem(strings.getString("edit") + "...");
menuItem.addActionListener(e1 -> edit());
popup.add(menuItem);
menuItem = new JMenuItem(strings.getString("remove") + "...");
menuItem.addActionListener(e1 -> remove());
popup.add(menuItem);
menuItem = new JMenuItem("Export to file...");
menuItem.addActionListener(e1 -> exportLayer(layer));
popup.add(menuItem);
JMenu paletteMenu = new JMenu("Move to palette");
for (final Palette palette : paletteManager.getPalettes()) {
menuItem = new JMenuItem(palette.getName());
menuItem.addActionListener(e1 -> moveLayerToPalette(layer, palette));
if (palette.contains(layer)) {
menuItem.setEnabled(false);
}
paletteMenu.add(menuItem);
}
menuItem = new JMenuItem("New palette...");
menuItem.addActionListener(e1 -> createNewLayerPalette(layer));
paletteMenu.add(menuItem);
popup.add(paletteMenu);
List<Action> actions = layer.getActions();
if (actions != null) {
for (Action action : actions) {
action.putValue(CustomLayer.KEY_DIMENSION, dimension);
popup.add(new JMenuItem(action));
}
}
popup.show(button, e.getX(), e.getY());
}
private void edit() {
int previousColour = layer.getColour();
WorldPainterDialog dialog;
if ((layer instanceof Bo2Layer) || (layer instanceof GroundCoverLayer) || (layer instanceof CombinedLayer) || (layer instanceof PlantLayer)) {
dialog = new EditLayerDialog<Layer>(App.this, layer);
} else if (layer instanceof UndergroundPocketsLayer) {
dialog = new UndergroundPocketsDialog(App.this, (UndergroundPocketsLayer) layer, selectedColourScheme, dimension.getMaxHeight(), world.isExtendedBlockIds());
} else if (layer instanceof TunnelLayer) {
final int baseHeight, waterLevel;
final TileFactory tileFactory = dimension.getTileFactory();
if (tileFactory instanceof HeightMapTileFactory) {
baseHeight = (int) ((HeightMapTileFactory) tileFactory).getBaseHeight();
waterLevel = ((HeightMapTileFactory) tileFactory).getWaterHeight();
} else {
baseHeight = 58;
waterLevel = 62;
}
dialog = new TunnelLayerDialog(App.this, (TunnelLayer) layer, world.isExtendedBlockIds(), selectedColourScheme, dimension.getMaxHeight(), baseHeight, waterLevel);
} else {
throw new RuntimeException("Don't know how to edit " + layer.getName());
}
dialog.setVisible(true);
if (!dialog.isCancelled()) {
button.setText(layer.getName());
button.setToolTipText(layer.getName() + ": " + layer.getDescription() + "; right-click for options");
int newColour = layer.getColour();
boolean viewRefreshed = false;
if (newColour != previousColour) {
button.setIcon(new ImageIcon(layer.getIcon()));
view.refreshTilesForLayer(layer, false);
viewRefreshed = true;
}
dimension.setDirty(true);
if (layer instanceof CombinedLayer) {
updateHiddenLayers();
}
if ((layer instanceof TunnelLayer) && (!viewRefreshed)) {
view.refreshTilesForLayer(layer, false);
}
}
}
private void remove() {
if (showConfirmDialog(App.this, MessageFormat.format(strings.getString("are.you.sure.you.want.to.remove.the.0.layer"), layer.getName()), MessageFormat.format(strings.getString("confirm.0.removal"), layer.getName()), YES_NO_OPTION) == YES_OPTION) {
deleteCustomLayer(layer);
// Doesn't happen automatically for some reason; Swing bug?
App.this.validate();
}
}
});
return buttonComponents;
}
Aggregations