/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/
package alluxio.client.file.options;
import alluxio.CommonTestUtils;
import alluxio.Configuration;
import alluxio.Constants;
import alluxio.PropertyKey;
import alluxio.client.WriteType;
import alluxio.security.authorization.Mode;
import alluxio.thrift.CreateDirectoryTOptions;
import alluxio.wire.TtlAction;
import org.junit.Assert;
import org.junit.Test;
import java.util.Random;
/**
* Tests for the {@link CreateDirectoryOptions} class.
*/
public final class CreateDirectoryOptionsTest {
private final WriteType mDefaultWriteType =
Configuration.getEnum(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.class);
@Test
public void defaults() {
CreateDirectoryOptions options = CreateDirectoryOptions.defaults();
Assert.assertFalse(options.isAllowExists());
Assert.assertFalse(options.isRecursive());
Assert.assertEquals(Constants.NO_TTL, options.getTtl());
Assert.assertEquals(TtlAction.DELETE, options.getTtlAction());
Assert.assertEquals(mDefaultWriteType, options.getWriteType());
Assert.assertEquals(Mode.defaults().applyDirectoryUMask(), options.getMode());
}
/**
* Tests getting and setting fields.
*/
@Test
public void fields() {
Random random = new Random();
boolean allowExists = random.nextBoolean();
boolean recursive = random.nextBoolean();
Mode mode = new Mode((short) random.nextInt());
long ttl = random.nextLong();
WriteType writeType = WriteType.NONE;
CreateDirectoryOptions options = CreateDirectoryOptions.defaults();
options.setAllowExists(allowExists);
options.setMode(mode);
options.setTtl(ttl);
options.setTtlAction(TtlAction.FREE);
options.setRecursive(recursive);
options.setWriteType(writeType);
Assert.assertEquals(allowExists, options.isAllowExists());
Assert.assertEquals(mode, options.getMode());
Assert.assertEquals(recursive, options.isRecursive());
Assert.assertEquals(ttl, options.getTtl());
Assert.assertEquals(TtlAction.FREE, options.getTtlAction());
Assert.assertEquals(writeType, options.getWriteType());
}
/**
* Tests conversion to thrift representation.
*/
@Test
public void toThrift() {
Random random = new Random();
boolean allowExists = random.nextBoolean();
boolean recursive = random.nextBoolean();
Mode mode = new Mode((short) random.nextInt());
long ttl = random.nextLong();
WriteType writeType = WriteType.NONE;
CreateDirectoryOptions options = CreateDirectoryOptions.defaults();
options.setAllowExists(allowExists);
options.setMode(mode);
options.setTtl(ttl);
options.setTtlAction(TtlAction.FREE);
options.setRecursive(recursive);
options.setWriteType(writeType);
CreateDirectoryTOptions thriftOptions = options.toThrift();
Assert.assertEquals(allowExists, thriftOptions.isAllowExists());
Assert.assertEquals(recursive, thriftOptions.isRecursive());
Assert.assertEquals(writeType.isThrough(), thriftOptions.isPersisted());
Assert.assertEquals(ttl, thriftOptions.getTtl());
Assert.assertEquals(alluxio.thrift.TTtlAction.Free, thriftOptions.getTtlAction());
Assert.assertEquals(mode.toShort(), thriftOptions.getMode());
}
@Test
public void equalsTest() throws Exception {
CommonTestUtils.testEquals(CreateDirectoryOptions.class);
}
}