<commit_before>/**
 * Copyright 2013 Cloudera Inc.
 *
 * Licensed 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 com.cloudera.data.filesystem;

import java.io.IOException;

import org.apache.avro.Schema;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.cloudera.data.DatasetDescriptor;
import com.cloudera.data.MetadataProvider;
import com.google.common.io.Files;
import com.google.common.io.Resources;

public class TestFileSystemMetadataProvider {

  private FileSystem fileSystem;
  private Path testDirectory;

  @Before
  public void setUp() throws IOException {
    fileSystem = FileSystem.get(new Configuration());
    testDirectory = new Path(Files.createTempDir().getAbsolutePath());
  }

  @After
  public void tearDown() throws IOException {
    fileSystem.delete(testDirectory, true);
  }

  @Test
  public void testNonPartitioned() throws IOException {
    MetadataProvider provider = new FileSystemMetadataProvider(fileSystem,
        testDirectory);

    Schema userSchema = new Schema.Parser().parse(Resources.getResource(
        "schema/user.avsc").openStream());

    provider.save("test", new DatasetDescriptor.Builder().schema(userSchema)
        .get());

    Assert.assertTrue(fileSystem.exists(new Path(testDirectory,
        "test/descriptor.avro")));

    DatasetDescriptor descriptor = provider.load("test");

    Assert.assertNotNull(descriptor);
    Assert.assertNotNull(descriptor.getSchema());
    Assert.assertFalse(descriptor.isPartitioned());
    Assert.assertEquals("user", descriptor.getSchema().getName());
  }

  @Test
  public void testPartitioned() throws IOException {
    MetadataProvider provider = new FileSystemMetadataProvider(fileSystem,
        testDirectory);

    Schema userSchema = new Schema.Parser().parse(Resources.getResource(
        "schema/user-partitioned.avsc").openStream());

    provider.save(
        "test",
        new DatasetDescriptor.Builder()
            .schema(userSchema)
            .partitionStrategy(
                new PartitionExpression(userSchema
                    .getProp("cdk.partition.expression"), true).evaluate())
            .get());

    Assert.assertTrue(fileSystem.exists(new Path(testDirectory,
        "test/descriptor.avro")));
  }

}
<commit_msg>Added a delete test for FileSystemMetadataProvider.<commit_after>/**
 * Copyright 2013 Cloudera Inc.
 *
 * Licensed 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 com.cloudera.data.filesystem;

import java.io.IOException;

import org.apache.avro.Schema;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.cloudera.data.DatasetDescriptor;
import com.cloudera.data.MetadataProvider;
import com.google.common.io.Files;
import com.google.common.io.Resources;

public class TestFileSystemMetadataProvider {

  private FileSystem fileSystem;
  private Path testDirectory;

  @Before
  public void setUp() throws IOException {
    fileSystem = FileSystem.get(new Configuration());
    testDirectory = new Path(Files.createTempDir().getAbsolutePath());
  }

  @After
  public void tearDown() throws IOException {
    fileSystem.delete(testDirectory, true);
  }

  @Test
  public void testNonPartitioned() throws IOException {
    MetadataProvider provider = new FileSystemMetadataProvider(fileSystem,
        testDirectory);

    Schema userSchema = new Schema.Parser().parse(Resources.getResource(
        "schema/user.avsc").openStream());

    provider.save("test", new DatasetDescriptor.Builder().schema(userSchema)
        .get());

    Assert.assertTrue(fileSystem.exists(new Path(testDirectory,
        "test/descriptor.avro")));

    DatasetDescriptor descriptor = provider.load("test");

    Assert.assertNotNull(descriptor);
    Assert.assertNotNull(descriptor.getSchema());
    Assert.assertFalse(descriptor.isPartitioned());
    Assert.assertEquals("user", descriptor.getSchema().getName());
  }

  @Test
  public void testDelete() throws IOException {
    MetadataProvider provider = new FileSystemMetadataProvider(fileSystem,
        testDirectory);

    provider.save(
        "test",
        new DatasetDescriptor.Builder().schema(
            Resources.getResource("schema/user.avsc")).get());

    Assert.assertTrue(fileSystem.exists(new Path(testDirectory,
        "test/descriptor.avro")));

    boolean result = provider.delete("test");
    Assert.assertTrue(result);

    result = provider.delete("test");
    Assert.assertFalse(result);
  }

  @Test
  public void testPartitioned() throws IOException {
    MetadataProvider provider = new FileSystemMetadataProvider(fileSystem,
        testDirectory);

    Schema userSchema = new Schema.Parser().parse(Resources.getResource(
        "schema/user-partitioned.avsc").openStream());

    provider.save(
        "test",
        new DatasetDescriptor.Builder()
            .schema(userSchema)
            .partitionStrategy(
                new PartitionExpression(userSchema
                    .getProp("cdk.partition.expression"), true).evaluate())
            .get());

    Assert.assertTrue(fileSystem.exists(new Path(testDirectory,
        "test/descriptor.avro")));
  }

}

{'fraction_non_alphanumeric': 0.10666666666666667, 'fraction_numerical': 0.00248062015503876, 'mean_word_length': 3.7998511904761907, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4362985', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1686, 'n_words': 433}